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
New feautre: @JsonIgnoreIf on base 2.14 #3375
base: 2.14
Are you sure you want to change the base?
Conversation
JsonIgnoreValidator jsonIgnoreValidator = jsonIgnoreIfAnn.value().newInstance(); | ||
return jsonIgnoreValidator.ignore(); | ||
} catch (InstantiationException | IllegalAccessException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
um, definitely not. :)
JsonIgnoreIf jsonIgnoreIfAnn = _findAnnotation(a, JsonIgnoreIf.class); | ||
if(jsonIgnoreIfAnn != null) { | ||
try { | ||
JsonIgnoreValidator jsonIgnoreValidator = jsonIgnoreIfAnn.value().newInstance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be changed, handlers would need to be instantiated using HandlerInstantiator
as is done with other helper objects. Alas, method is not yet passed MapperConfig
and it's not trivial to get it there...
src/main/java/com/fasterxml/jackson/databind/deser/JsonIgnoreValidator.java
Show resolved
Hide resolved
Ok, I think that if this was to be merged, I'd like to make this bit more contextual, partly to allow But what I am also thinking is this: I am not 100% sure this makes sense as an out-of-the-box feature, because you can actually implement this by custom So at this point I am still evaluating whether this should be included, and if so in what form. But I will keep thinking about it: I think the idea is good, I am just not sure how it should be supported. |
Hello everyone,
We discussed this new feature already in a closed PR. It was on the wrong branch. Therefore here on branch 2.14:
In several projects (especially REST APIs) in which I used Jackson I needed the feature to ignore an Jackson property dynamically (e.g. based on authorization). I always used some kind of workaround.
So I decided to build the @JsonIgnoreIf annotation. You can specify a class extending the abstract class JsonIgnoreValidator.
The usage is basically very easy.
Defining properties that should be checked before transfering into JSON works by:
Best regards from Germany
Sebastian