I would like to avoid adding the annotation @JsonIgnoreProperties(ignoreUnknown = true) on every class, is it possible to add a configuration for that purpose?
I was thinking of something like:
spring.jackson.default-property-ignore=ignore_unknown
Comment From: philwebb
@leocwolter Can you use a Jackson2ObjectMapperBuilderCustomizer bean and call mixIn(Object.class, MixinAnnotations.class) to do this?
Comment From: philwebb
Oh wait. I misread your initial comment. I think we set ignoreUnknown for unknown properties by default. Can you share a sample that shows what you're trying to do?
Comment From: philwebb
See #1237. We do have DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES defaulting to false already.
Comment From: agogs
You can usespring.jackson.deserialization.fail-on-unknown-properties=false
Comment From: vfonic
@agogs does this ignore unknown properties or lets them through? I don't want the user to be able to submit whatever they want. I want to explicitly accept only the properties I allow and ignore anything else. Is that possible?
Comment From: snicoll
@vfonic please ask questions on StackOverflow.
Comment From: jlous
The spring default and spring override do not apply to the objectmapper Hibernate uses. Customising parsing for json columns in spring is still impenetrable magic.
Comment From: wilkinsona
Prior to Hibernate 6 (which is not yet supported), I don't think Hibernate uses Jackson. To double-check, I prepped Hibernate's 5.6.9 tag and found no occurrences of jackson.
If you think there's something that Spring Boot should be configuring with the main ObjectMapper, please open a new issue and we can take a look. We'll need to know exactly where that ObjectMapper is being used. A small sample that reproduces the problem you're facing is the ideal way to show us.
Comment From: jlous
Ok. I just saw a way of making hibernate use spring's objectmapper (https://stackoverflow.com/questions/66656772/use-jackson-objectmapper-configured-by-spring-boot-in-hibernate) so I assumed it used a similar one by default.
I do wish there was a simple way to achieve this with regular spring configs
Comment From: wilkinsona
The person who asked that question is using Hibernate Types, a library that builds on top of Hibernate. Boot knows nothing about it so it isn't something that we can configure automatically.