Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#893 Disable Jackson ObjectMapper FAIL_ON_UNKNOWN_PROPERTIES Deserialization Feature by default #894

Closed
wants to merge 1 commit into from

Conversation

amiriahmad72
Copy link
Contributor

@amiriahmad72 amiriahmad72 commented Jan 17, 2024

Edit JacksonDeserializer constructor with claimTypeMap argument:

public JacksonDeserializer(Map<String, Class<?>> claimTypeMap) {
    this(claimTypeMap, false);
}

public JacksonDeserializer(Map<String, Class<?>> claimTypeMap, boolean failOnUnknownProperties) {
    // DO NOT reuse JacksonSerializer.DEFAULT_OBJECT_MAPPER as this could result in sharing the custom deserializer
    // between instances
    this(new ObjectMapper());
    Assert.notNull(claimTypeMap, "Claim type map cannot be null.");
    // register a new Deserializer
    SimpleModule module = new SimpleModule();
    module.addDeserializer(Object.class, new MappedTypeDeserializer(Collections.unmodifiableMap(claimTypeMap)));
    objectMapper.registerModule(module);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, failOnUnknownProperties);
}

in order to disable Jackson ObjectMapper FAIL_ON_UNKNOWN_PROPERTIES Deserialization Feature by default .

Closes #893

@lhazlewood
Copy link
Contributor

@amiriahmad72 Thanks for this! But oddly enough, it appears we were working on two nearly identical things at the same time. I opened #895 recently.

After that's merged, would you like to change this PR to work with that code change? Some cleanup was done that should enable your addition to be done simply without overloading a constructor.

@lhazlewood
Copy link
Contributor

@amiriahmad72 also we'll need a test case to assert the behavior works as expected (and remains working for regression purposes on future builds/releases).

@amiriahmad72
Copy link
Contributor Author

Thanks alot @lhazlewood
I close this PR and reopen another one that I use your codes and also add specific test case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable Jackson ObjectMapper FAIL_ON_UNKNOWN_PROPERTIES Deserialization Feature
2 participants