我试图ObjectMapper为内置的play.libs.Json. 我遵循了文档,但是 MapperLoader 似乎被忽略了。
这就是我所做的(基于文档):
创建 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"
当我序列化日期时,它仍然给我时间戳而不是指定的格式。
我有几个解决方法:
- 我在创建过程中设置了对象映射器
ApplicationController - 我禁用
play.core.ObjectMapperProvider并启用我的CustomObjectMapperProvider.
这个问题有更好的选择吗?
感谢和问候,