2016-06-27 18 views
0

我试图配置内置play.libs.JsonObjectMapper。我跟着文档,但MapperLoader似乎被忽略。更改播放2.5的JsonConverter日期格式

这是我做什么(基于文档):

  • 创建CustomMapperLoader public class JsonMapperLoader extends GuiceApplicationLoader { @Override public GuiceApplicationBuilder builder(final Context context) { ObjectMapper mapper = Json.newDefaultMapper() .setDateFormat(new SimpleDateFormat(Constants.ISO8601_DATE_FORMAT)); Json.setObjectMapper(mapper); return super.builder(context); } }

  • 显式加载装载机application.conf:

play.application.loader = "JsonMapperLoader"

当我序列化日期时,它仍然给我时间戳而不是指定的格式。

我有几个解决方法如下:

  1. 我创作的 ApplicationController
  2. 期间设置的对象映射器I禁用play.core.ObjectMapperProvider,使我CustomObjectMapperProvider

这个问题有没有更好的选择?

感谢&问候,

回答

0

我没试过的方法中的说明书(含定制ApplicationLoader)中所建议。我使用另一种技术。简而言之:有一个类,它配置ObjectMapper;该类将作为一个单元注入模块中。

您可以看到完整的代码示例here