So using a mixin did NOT work. Here's the mixin:interface DisableAdditionalPropertiesMixIn {@JsonIgnoreMap<String, Object> getAdditionalProperties();@JsonIgnorevoid setAdditionalProperty(String name, Object value);}m.addMixInAnnotations(Data.class, DisableAdditionalPropertiesMixIn.class);This basically did nothing. My guess is that mixins only allow you to add OR override any existing annotation, but not remove it/ignore it unless the annotation itself supports some flag you can set to disable it.
So instead, I did this:public class IgnoreAdditionalPropertiesInspector extends JacksonAnnotationIntrospector {@Overridepublic boolean hasAnySetterAnnotation(AnnotatedMethod am) {return false;}@Overridepublic boolean hasAnyGetterAnnotation(AnnotatedMethod am) {return false;}}JacksonAnnotationIntrospector introspector = new IgnoreAdditionalPropertiesInspector();m.setAnnotationIntrospector(introspector);This works! woohoo!
However, I'm curious if there's any better way to achieve this or is this the recommended approach?
Thanks!
On Friday, September 9, 2016 at 6:50:48 PM UTC-4, Brent Ryan wrote:I'm going to attempt to do this by just creating a DisableAdditionalPropertiesMixin class that I can apply. I'm not sure this will work and it kinda sucks because it means that the only way for it to work for everything is to apply this to every Object in the hierarchy.Any other ideas here?
On Friday, September 9, 2016 at 6:07:47 PM UTC-4, Brent Ryan wrote:We're looking to see if there's a way to use the same model with @JsonAnySetter jackson pattern for serialization to backend data storage, while allowing us to use the same models for the inbound API requests that are more strict. So we want FAIL_ON_UNKNOWN_PROPERTIES set to true and @JsonAnySetter to be disabled from the API perspective.Is there a way to do this or do you have to have 2 separate models or use mix-ins? Looking for the preferred approach to dealing with this.Example class:public class Data {@JsonIgnoreprivate Map<String, Object> additionalProperties = new HashMap<String, Object>();@JsonAnyGetterpublic Map<String, Object> getAdditionalProperties() {return this.additionalProperties;}@JsonAnySetterpublic void setAdditionalProperty(String name, Object value) {this.additionalProperties.put(name, value);}}Is there a way to disable a feature in ObjectMapper that turns off the JsonAnySetter/JsonAnyGetter for 1 use case, but then enables it for others?
--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscribe@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscribe@googlegroups.com.