FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.51k stars 1.37k forks source link

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

Open anand188 opened 1 month ago

anand188 commented 1 month ago

Search before asking

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

cowtowncoder commented 1 month ago

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.

anand188 commented 4 weeks ago

@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

cowtowncoder commented 4 weeks ago

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

anand188 commented 3 weeks ago

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

JooHyukKim commented 3 weeks ago

@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

cowtowncoder commented 3 weeks ago

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.

anand188 commented 3 weeks ago

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.

yihtserns commented 3 weeks ago

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

cowtowncoder commented 2 weeks ago

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)

anand188 commented 2 weeks ago

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

cowtowncoder commented 2 weeks ago

@anand188 I don't understand the question.