我正在用 JSR310 替换 JodaTime,并且 JodaTime() 的模块工作正常。
我正在尝试在 spring-boot 应用程序中重新配置日期的序列化。
我不能同时保留两者,所以我正在寻找一种将我的日期序列化/反序列化为 ISO 8601 的方法。
我遵循了这里的建议,但这没有帮助:http : //lewandowski.io/2016/02/formatting-java-time-with-spring-boot-using-json/
这是我JacksonConfig.java的objectMapper:
@Configuration
public class JacksonConfig extends RepositoryRestMvcConfiguration {
private static final Logger logger = LoggerFactory.getLogger(JacksonConfig.class);
public static final DateTimeFormatter FORMATTER = ofPattern("dd::MM::yyyy");
@Bean
// Override and Primary due to bug: https://github.com/spring-projects/spring-boot/issues/6529
@Override
@Primary
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer());
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer());
mapper.registerModule(javaTimeModule); …Run Code Online (Sandbox Code Playgroud)