Jackson ObjectMapper: Difference between revisions
(Created page with "=Internal= * Jackson =Overview= =Configuration=") |
|||
Line 6: | Line 6: | ||
=Configuration= | =Configuration= | ||
==Mapper Features== | |||
====Annotation Use==== | |||
<tt>ObjectMapper</tt> can be configured to use or not annotation introspection. By default is true. | |||
<syntaxhighlight lang='java'> | |||
om.configure(MapperFeature.USE_ANNOTATIONS, true); | |||
</syntaxhighlight> | |||
====Use Getters as Setters==== | |||
This feature determines whether the "getter" methods that handle Collections and Maps can be used for purpose of getting a reference to a Collection and Map to modify the property, without requiring a setter method. This is similar to how JAXB framework sets Collections and Maps. Note that such getters-as-setters methods have lower precedence than setters, so they are only used if no setter is found for the Map/Collection property. The feature is enabled by default. | |||
<syntaxhighlight lang='java'> | |||
om.configure(MapperFeature.USE_GETTERS_AS_SETTERS, true); | |||
</syntaxhighlight> | |||
====Propagate Transient Marker==== | |||
This feature determines how <tt>transient</tt> modifier for fields is handled: if disabled, it is only taken to mean exclusion of the field as accessor; if true, it is taken to imply removal of the whole property. Feature is disabled by default, meaning that existence of <tt>transient</tt> for a field does not cause Jackson to ignore getters or setters just ignoring the use of field for access. | |||
<syntaxhighlight lang='java'> | |||
om.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, false); | |||
</syntaxhighlight> | |||
==Deserialization Features== | |||
====Fail on Ignored Properties==== | |||
This feature determines what happens when a property that has been explicitly marked as ignorable is encountered in input: if feature is enabled, JsonMappingException is thrown; if false, property is quietly skipped. The feature is disabled by default so that no exception is thrown. Another way to look at it is as configuration to ignore fields that appear in the JSON serialized format, but are not declared as members in the type. The same effect can be achieved by annotating the type with [[@JsonIgnoreProperties]] | |||
<syntaxhighlight lang='java'> | |||
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | |||
</syntaxhighlight> |
Revision as of 01:58, 14 November 2018
Internal
Overview
Configuration
Mapper Features
Annotation Use
ObjectMapper can be configured to use or not annotation introspection. By default is true.
om.configure(MapperFeature.USE_ANNOTATIONS, true);
Use Getters as Setters
This feature determines whether the "getter" methods that handle Collections and Maps can be used for purpose of getting a reference to a Collection and Map to modify the property, without requiring a setter method. This is similar to how JAXB framework sets Collections and Maps. Note that such getters-as-setters methods have lower precedence than setters, so they are only used if no setter is found for the Map/Collection property. The feature is enabled by default.
om.configure(MapperFeature.USE_GETTERS_AS_SETTERS, true);
Propagate Transient Marker
This feature determines how transient modifier for fields is handled: if disabled, it is only taken to mean exclusion of the field as accessor; if true, it is taken to imply removal of the whole property. Feature is disabled by default, meaning that existence of transient for a field does not cause Jackson to ignore getters or setters just ignoring the use of field for access.
om.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, false);
Deserialization Features
Fail on Ignored Properties
This feature determines what happens when a property that has been explicitly marked as ignorable is encountered in input: if feature is enabled, JsonMappingException is thrown; if false, property is quietly skipped. The feature is disabled by default so that no exception is thrown. Another way to look at it is as configuration to ignore fields that appear in the JSON serialized format, but are not declared as members in the type. The same effect can be achieved by annotating the type with @JsonIgnoreProperties
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);