jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Deserialization: fail-on-unknown-properties: false is not working getting Unrecognized field "xxyyzz"

Open anand188 opened this issue 1 year ago • 11 comments

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

anand188 avatar Aug 05 '24 13:08 anand188

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 avatar Aug 12 '24 00:08 cowtowncoder

@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 image

anand188 avatar Aug 13 '24 16:08 anand188

@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 avatar Aug 14 '24 00:08 cowtowncoder

@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 avatar Aug 21 '24 10:08 anand188

@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

JooHyukKim avatar Aug 21 '24 11:08 JooHyukKim

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.

cowtowncoder avatar Aug 21 '24 18:08 cowtowncoder

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 avatar Aug 22 '24 12:08 anand188

@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.

yihtserns avatar Aug 22 '24 12:08 yihtserns

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 avatar Aug 22 '24 16:08 cowtowncoder

@cowtowncoder just want to make sure "@jsonignoreproperties" if this annotation is not used does it override any the configuration set in Objectmapper ?

anand188 avatar Aug 23 '24 11:08 anand188

@anand188 I don't understand the question.

cowtowncoder avatar Aug 23 '24 14:08 cowtowncoder

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.

golimpio avatar Nov 19 '24 10:11 golimpio

No reproduction, closing.

cowtowncoder avatar Nov 19 '24 23:11 cowtowncoder

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.

hohwille avatar Nov 11 '25 08:11 hohwille

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.

@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.

pjfanning avatar Nov 11 '25 09:11 pjfanning