New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonViewSupportFactoryBean breaks jackson-datatype-jsr310 #49
Comments
That's odd, it should be supported. There's code specifically delegating JSR310 serialization here: https://github.com/monitorjbl/json-view/blob/master/json-view/src/main/java/com/monitorjbl/json/JsonViewSerializer.java#L186. there's also a test case for it here: https://github.com/monitorjbl/json-view/blob/master/json-view/src/test/java/com/monitorjbl/json/JsonViewSerializerTest.java#L779 . Did you only include the JsonViewModule in your mapper? You need to include both if you haven't. |
I'm sure my shallow knowledge of the Spring Framework is the root of the problem here.. I managed to get the result I wanted by initializing @Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
return builder
.createXmlMapper(false)
.build()
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
@Autowired
private MappingJackson2HttpMessageConverter converter;
@Bean
public JsonViewSupportFactoryBean views() {
return new JsonViewSupportFactoryBean(converter.getObjectMapper());
} In my opinion this looks quite odd and I'm sure there is a better way to do this. Internet seems a bit confused as to how the Would you care to shed some light on this for me, oh great one? |
My guess is that those are not the same ObjectMapper objects. You might want to try explicitly creating another mapper with the correct properties to see if that fixes the problem. If it does, you can find some way to write in the ObjectMapper instance you made in the objectMapper() method. |
I've had the same issue. Is it possible that @Bean
public JsonViewSupportFactoryBean views() {
// no object mapper in constructor
return new JsonViewSupportFactoryBean();
} overwrites the spring configuration for jackson? |
I would first like to say that what you've done here is brilliant; it was exactly what I was looking for.
However, when I define the
@Bean
as you suggest in the README, myLocalDateTime
fields are no longer correctly serialized. I usejackson-datatype-jsr310
in order to serialize these fields in the correct way, but when I write:this no longer works and I get a very weird JSON blob from the serialization.
My gradle dependencies are the following:
Do you have any ideas why this is happening?
The text was updated successfully, but these errors were encountered: