Spring Jackson custom Deserializer does not called
491
Thanks the help for everyone. Finally I found the answer at spring.io.
@Configuration
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.deserializerByType(Date.class, new DateDeserializer());
converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
}
}
Related videos on Youtube
Author by
user3057944
Updated on January 01, 2023Comments
-
user3057944 over 1 year
I have a Spring project, and I try to add a custom deserializer to deserialize Date properties depend on their format. If I use it as annotation on Date property, it works fine. But if I add the deserializer to my object mapper, it does not called when Jackson deserialize a date.
I try to apply my custom deserializer like this:
@Bean public ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addDeserializer(Date.class, new DateDeserializer()); mapper.registerModule(module); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false); mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false); mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); return mapper; }
I don't want to apply an annotation on Date properties every time, I want to use this deserializer by default. What I do wrong?
-
jmiguel over 10 yearsThat's the problem, it's NOT running, or at least there's no process, no indication at all of the program running and how could there be if I deleted the installation folder in which the path to executable was: C:\Program Files (x86)\Faronics\Deep Freeze\Install\C-0\DFServ.exe. But somehow it waited for the 5 or 6 thawed reboots I mentioned earlier and now it's back on business freezing C: again. Main problem: I don't have installation folder so I can't uninstall it, is there any other approach to fix this that doesn't need uninstalling the program to make it stop working???
-
jmiguel over 10 yearsNo, it won´t. When I run it, it displays the error message I wrote earlier: "Deep Freeze Standard must be disabled before any Install/Uninstall can proceed"
-
Kirk over 10 yearsI have no idea now but, Any SafeMode tries? did you try that?
-
Kirk over 10 yearscheck my updated post
-
Kirk over 10 yearsyes, maybe another PC, however you need that installation foler and files
-
jmiguel over 10 yearsOh, about that file Persi0.sys, yeah, I might have deleted it too, looks like I deleted all my options away,ggg.
-
jmiguel over 10 yearsthat's right, won't I get those if I install it in another pc, including the Persi0.sys file??
-
Kirk over 10 yearsyou just copy all files from new installation folder and try
-
user3057944 over 2 yearsI define ObjectMapper bean in '@Configuration' class. I don't want to use ObjectMapper "manually", I was told Jackson use that ObjectMapper defined at Bean. But it seems to it it does not.
-
user3057944 over 2 yearsYou could right, maybe Jackson does not use that ObjectMapper I define in my configuration class. So I added the Bean you advised, but when Jackson deserializing a Date, my deserializer still is not called.
-
João Dias over 2 yearsWell, then the only option is that you are importing a different
Date
in yourObjectMapper
than the one that you have in your model. It is highly unlikely that this is the case, but can you double-check it? Minor detail that is not related: you havemapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
duplicated in your configuration. -
ray over 2 yearsCan you add code for your
DateDeserializer
and add where you deserialize. -
ray over 2 yearsAlso make sure your configuration class in same
base-package
-
João Dias over 2 yearsGreat! You can upvote answers if they helped you ;)