0

Spring Boot sets "spring.jackson.deserialization.fail-on-unknown-properties=false" by default. I have a library that works fine in Spring Boot, but when used in an existing SpringMVC app it throws "Unrecognized field, not marked as ignorable". Is there some comparable global setting for SpringMVC I can set in the config or otherwise?

edit: spring webmvc version 3.2.15.RELEASE

bob
  • 37
  • 5

2 Answers2

1

You can annotate the mapped classes with

@JsonIgnoreProperties(ignoreUnknown = true)

or create add the following configuration to the ObjectMapper as follows:

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Shai Givati
  • 1,106
  • 1
  • 10
  • 24
1

You can follow two method that I have mention in this answer. If I'm not wrong either one will work for you. (But method 1 won't work if your clinet class does not have a no-arg default constructor)

ray
  • 1,512
  • 4
  • 11
  • Unfortunately Jackson2ObjectMapperBuilder isn't in spring 3.2.15; not until 4.1.1 I think. – bob Sep 04 '21 at 16:42
  • not yet, I tried your good idea of the custom de-serializer, but it doesn't work because I'm stuck with spring 3.2.15 for now. I will see if there is similar approach with that version tomorrow. thanks! – bob Sep 06 '21 at 15:30
  • @bob if you can share your code, it will be helpful – ray Sep 06 '21 at 17:04
  • Sorry, I don't have any code to share. I added a library that normally runs in spring boot to my already running springmvc app and it throws that exception. I was hoping there was some setting I could do to make it ignore unknown fields. – bob Sep 08 '21 at 10:27