Skip to content

On deserialization consider allowing fields in other views to be considered as unknown properties instead of silently ignoring them #4108

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

Closed
joca-bt opened this issue Sep 7, 2023 · 5 comments
Labels
2.16 Issues planned for 2.16

Comments

@joca-bt
Copy link

joca-bt commented Sep 7, 2023

Consider the following class

public class Test {
    public String nonViewField;
    @JsonView(View1.class)
    public String view1Field;
    @JsonView(View2.class)
    public String view2Field;
}

When deserializing the following JSON, an error will be raised as potato is an unknown property.

{
  "nonViewField": "value",
  "potato": 1
}

When deserializing the following JSON with View1, I would expect to get a similar error as before, stating view2Field is an unknown property, but instead it simply gets ignored (the field is set to null).

{
  "nonViewField": "value",
  "view1Field": "value",
  "view2Field": "value"
}

I tried enabling FAIL_ON_IGNORED_PROPERTIES but it didn't seem to affect this situation. Is this something that would be possible? Either via FAIL_ON_IGNORED_PROPERTIES or some other configuration?

This is helpful when we want to do versioning on a DTO in a declarative manner, for example.

@joca-bt joca-bt added the to-evaluate Issue that has been received but not yet evaluated label Sep 7, 2023
@joca-bt joca-bt changed the title On deserialization consider allow fields in other views to be considered as invalid instead of silently ignoring them On deserialization consider allowing fields in other views to be considered as unknown properties instead of silently ignoring them Sep 7, 2023
@cowtowncoder
Copy link
Member

I think we would consider a new DeserializationFeature to enable such behavior, if anyone was interested in trying to implement this functionality. I think this makes sense. Default behavior probably cannot be changed due to backwards-compatibility concerns.

@cowtowncoder cowtowncoder added 2.16 Issues planned for 2.16 and removed to-evaluate Issue that has been received but not yet evaluated labels Sep 8, 2023
@JooHyukKim
Copy link
Member

Just stoppying by with naming ideas 😆

  • DeserializationFeature.FAIL_ON_UNEXPECTED_VIEW_PROPERTIES
  • DeserializationFeature.FAIL_ON_MISMATCHED_VIEW_FIELDS
  • DeserializationFeature.STRICT_VIEW_PROPERTY_VALIDATION
  • DeserializationFeature.STRICT_VIEW_DESERIALIZATION
  • DeserializationFeature.REQUIRE_EXACT_MATCHING_VIEW

@cowtowncoder
Copy link
Member

I like the first option!

@JooHyukKim
Copy link
Member

@joca-bt PTAL at #4275 if it solves the discusssed problem?

@cowtowncoder
Copy link
Member

Ok, so this is dup of #437 so will close, but will be allowed with new DeserializationFeature.FAIL_ON_UNEXPECTED_VIEW_PROPERTIES in 2.17.0.

@cowtowncoder cowtowncoder closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.16 Issues planned for 2.16
Projects
None yet
Development

No branches or pull requests

3 participants