jackson-databind
jackson-databind copied to clipboard
Deserialization: fail-on-unknown-properties: false is not working getting Unrecognized field "xxyyzz"
Search before asking
- [X] I searched in the issues and found nothing similar.
Describe the bug
jackson: deserialization: fail-on-unknown-properties: false is not working getting Unrecognized field "xxyyzz"
Version Information
2.17.1
Reproduction
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY);
mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY);
mapper.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.PUBLIC_ONLY);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(SerializationFeature.FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(SerializationFeature.WRITE_DATES_WITH_ZONE_ID, true);
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
return mapper;
}
jackson: deserialization: fail-on-unknown-properties: false is not working getting Unrecognized field "xxyyzz"
Expected behavior
Should not get any exception , continue to work
Additional context
No response
Full reproduction needed: specifically, what kind of input is used; what POJO (class) is used and so on. Without that it is impossible to say what happens.
@cowtowncoder For example pojo has name , data but no id and immutable properties when API is invoked with id and immutable
Here always Deserialization Feature is not considered and executes else block expected to skip and continue
@anand188 Huh? I don't understand what you saying here. I did not ask for snippet of Jackson code but:
Full reproduction needed: ...
so please include reproduction of the problem.
@cowtowncoder question is configuration set on mapper will always propagated in Deserialization Context , i dont think so ,i am working on huge project which cannot be shared . Do you have test which can show this working ?
@anand188 The configuration in question has been working for a long time.
U are not asked to provide ur project's source code. But U need to provide at least full reproduction(or preferrably) simplified input, output, version information and test showing that what u r saying is happening. Otherwise can't properly get help.
PS: there is a bunch of test agaisnt the configuration. Please refer to the Jackson test suite. Just search it on ur editor
I don't understand at all what is being asked here. Leaving open for a bit for clarification, but will close unless there's pertinent new information.
let me add more insight @cowtowncoder @JooHyukKim the project uses spring boot and we have our own "@Bean " override Objectmapper with configuration to disable unknown properties. But even though this is overridden we are still seeing this is not enabled in Deserialization context and fails with error instead skipping/ignoring it. Sorry as this is huge project thats not simple to upload and dont get time try a sample spring boot to attach her but 100%sure something fishy in code or not documented how to use.
@anand188 I highly recommend that you get a senior developer in your team to go through this thread and help you provide a minimal reproducible example for this issue.
If this is due to Spring Boot configuration, issue belongs to SB trackers. Without Jackson-only reproduction we cannot really help here. (that is, no point in creating reproduction that relies on SB -- we won't be using that).
Will close; may be re-opened/re-filed with Jackson-only problem reproduction (but it sounds like this is about framework configuration)
@cowtowncoder just want to make sure "@jsonignoreproperties" if this annotation is not used does it override any the configuration set in Objectmapper ?
@anand188 I don't understand the question.
I've seen this issue, but it was caused by a race condition involving a shared ObjectMapper used by multiple threads, with its configuration being changed by another thread.
No reproduction, closing.
This bug still exists and can be reproduced with a single-threaded processing.
Just chain 2 records into each other.
Workaround is to add @JsonIgnoreProperties(ignoreUnknown = true) to each record.
Actually according to Jackson documentation disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) should be sufficient and no extra annotation @JsonIgnoreProperties(ignoreUnknown = true) would be required.
This bug still exists and can be reproduced with a single-threaded processing. Just chain 2 records into each other. Workaround is to add
@JsonIgnoreProperties(ignoreUnknown = true)to eachrecord. Actually according to Jackson documentationdisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)should be sufficient and no extra annotation@JsonIgnoreProperties(ignoreUnknown = true)would be required.
@hohwille can you raise a new issue with details about the jackson version that you are using. Also, a full POC would be appreciated. Jackson support for Java records has its own code so stuff that works with POJOs may not necessarily work with records so maybe that is a point to raise in the new issue is if what you are seeing is specific to records.