'spring jackson deserialization adjust_dates_to_context_time_zone ignored
I am trying to preserve the time zone that has been passed in the REST API, I have set
spring:
jackson:
deserialization:
adjust_dates_to_context_time_zone: false
Even tried using uppercase for adjust_dates_to_context_time_zone
But the field is always being converted to UTC:
@Data
@Builder
@ApiModel
@NoArgsConstructor
@AllArgsConstructor
public class RequestDTO {
private ZonedDateTime time;
}
I have even tried setting it in ObjectMapper Configuration:
@Configuration
public class ObjectMapperConfig {
@Bean
@Primary
public ObjectMapper objectMapper() {
return new ObjectMapper()
.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false); //double kill
}
}
Still the date is being converted to UTC. At this point, I dont know what else I should try or doing wrong. Any suggestions?
Im using Spring boot 2.4.2 and JDK 11
EDIT:
looks like this is happening, when include a WebMvcConfigurationSupport configuration.
@Configuration
public class WebConfig extends WebMvcConfigurationSupport { }
Solution 1:[1]
This configuration worked for me:
@Configuration
public class JacksonConfiguration {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> builder.featuresToDisable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); // make sure timezones are not being converted to GMT when parsing json
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stijn Hooft |
