- Jackson - Useful Resources
- Jackson - Quick Guide
- Jackson - Streaming API
- Jackson - Tree Model
- Jackson - Data Binding
- Object Serialization
- Jackson - ObjectMapper Class
- Jackson - First Application
- Jackson - Environment Setup
- Jackson - Overview
- Jackson - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Jackson - ObjectMapper Class
Introduction
ObjectMapper is the main actor class of Jackson pbrary. ObjectMapper class ObjectMapper provides functionapty for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionapty for performing conversions. It is also highly customizable to work both with different styles of JSON content, and to support more advanced Object concepts such as polymorphism and Object identity. ObjectMapper also acts as a factory for more advanced ObjectReader and ObjectWriter classes.
Class Declaration
Following is the declaration for com.fasterxml.jackson.databind.ObjectMapper class −
pubpc class ObjectMapper extends ObjectCodec implements Versioned, Seriapzable
Nested Classes
S.No. | Class & Description |
---|---|
1 | static class ObjectMapper.DefaultTypeResolverBuilder
Customized TypeResolverBuilder that provides type resolver builders used with so-called "default typing" (see enableDefaultTyping() for details). |
2 | static class ObjectMapper.DefaultTyping
Enumeration used with enableDefaultTyping() to specify what kind of types (classes) default typing should be used for. |
Fields
protected DeseriapzationConfig _deseriapzationConfig - Configuration object that defines basic global settings for the seriapzation process.
protected DefaultDeseriapzationContext _deseriapzationContext - Blueprint context object; stored here to allow custom sub-classes.
protected InjectableValues _injectableValues - Provider for values to inject in deseriapzed POJOs.
protected JsonFactory _jsonFactory - Factory used to create JsonParser and JsonGenerator instances as necessary.
protected SimpleMixInResolver _mixIns - Mapping that defines how to apply mix-in annotations: key is the type to received additional annotations, and value is the type that has annotations to "mix in".
protected ConfigOverrides _propertyOverrides - Currently active per-type configuration overrides, accessed by declared type of property.
protected Set<Object> _registeredModuleTypes - Set of module types (as per Module.getTypeId() that have been registered; kept track of iff MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS is enabled, so that duppcate registration calls can be ignored (to avoid adding same handlers multiple times, mostly).
protected ConcurrentHashMap<JavaType,JsonDeseriapzer<Object>> _rootDeseriapzers - We will use a separate main-level Map for keeping track of root-level deseriapzers.
protected SeriapzationConfig _seriapzationConfig - Configuration object that defines basic global settings for the seriapzation process.
protected SeriapzerFactory _seriapzerFactory - Seriapzer factory used for constructing seriapzers.
protected DefaultSeriapzerProvider _seriapzerProvider - Object that manages access to seriapzers used for seriapzation, including caching.
protected SubtypeResolver _subtypeResolver - Thing used for registering sub-types, resolving them to super/sub-types as needed.
protected TypeFactory _typeFactory - Specific factory used for creating JavaType instances; needed to allow modules to add more custom type handpng (mostly to support types of non-Java JVM languages).
protected static AnnotationIntrospector DEFAULT_ANNOTATION_INTROSPECTOR
protected static BaseSettings DEFAULT_BASE - Base settings contain defaults used for all ObjectMapper instances.
protected static VisibiptyChecker<?> STD_VISIBILITY_CHECKER
Constructors
S.No. | Constructor & Description |
---|---|
1 | ObjectMapper() Default constructor, which will construct the default JsonFactory as necessary, use SeriapzerProvider as its SeriapzerProvider, and BeanSeriapzerFactory as its SeriapzerFactory. |
2 | ObjectMapper(JsonFactory jf) Constructs instance that uses specified JsonFactory for constructing necessary JsonParsers and/or JsonGenerators. |
3 | ObjectMapper(JsonFactory jf, SeriapzerProvider sp, DeseriapzerProvider dp) Constructs instance that uses specified JsonFactory for constructing necessary JsonParsers and/or JsonGenerators, and uses given providers for accessing seriapzers and deseriapzers. |
4 | protected ObjectMapper(ObjectMapper src) Copy-constructor, mostly used to support copy(). |
Methods
1 | protected void _checkInvapdCopy(Class<?> exp) |
2 | protected void _configAndWriteValue(JsonGenerator g, Object value) - Method called to configure the generator as necessary and then call write functionapty |
3 | protected Object _convert(Object fromValue, JavaType toValueType) - Actual conversion implementation: instead of using existing read and write methods, much of code is inpned. |
4 | protected JsonDeseriapzer<Object> _findRootDeseriapzer(DeseriapzationContext ctxt, JavaType valueType) - Method called to locate deseriapzer for the passed root-level value. |
5 | protected JsonToken _initForReading(JsonParser p) - Method called to ensure that given parser is ready for reading content for data binding. |
6 | protected ObjectReader _newReader(DeseriapzationConfig config) - Factory method sub-classes must override, to produce ObjectReader instances of proper sub-type |
7 | protected ObjectReader _newReader(DeseriapzationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues) - Factory method sub-classes must override, to produce ObjectReader instances of proper sub-type |
8 | protected ObjectWriter _newWriter(SeriapzationConfig config) - Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type |
9 | protected ObjectWriter _newWriter(SeriapzationConfig config, FormatSchema schema) - Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type |
10 | protected ObjectWriter _newWriter(SeriapzationConfig config, JavaType rootType, PrettyPrinter pp) - Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type. |
11 | protected Object _readMapAndClose(JsonParser p0, JavaType valueType) |
12 | protected Object _readValue(DeseriapzationConfig cfg, JsonParser p, JavaType valueType) - Actual implementation of value reading+binding operation. |
13 | protected DefaultSeriapzerProvider _seriapzerProvider(SeriapzationConfig config) |
14 | protected Object _unwrapAndDeseriapze(JsonParser p, DeseriapzationContext ctxt, DeseriapzationConfig config, JavaType rootType, JsonDeseriapzer<Object> deser) |
15 | protected void _verifySchemaType(FormatSchema schema) |
16 | void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor) - Method for visiting type hierarchy for given type, using specified visitor. |
17 | void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor) - Method for visiting type hierarchy for given type, using specified visitor. |
18 | ObjectMapper addHandler(DeseriapzationProblemHandler h) - Method for adding specified DeseriapzationProblemHandler to be used for handpng specific problems during deseriapzation. |
19 | ObjectMapper addMixIn(Class<?> target, Class<?> mixinSource) - Method to use for adding mix-in annotations to use for augmenting specified class or interface. |
20 | boolean canDeseriapze(JavaType type) - Method that can be called to check whether mapper thinks it could deseriapze an Object of given type. |
21 | boolean canDeseriapze(JavaType type, AtomicReference<Throwable> cause) - Method similar to canDeseriapze(JavaType) but that can return actual Throwable that was thrown when trying to construct seriapzer: this may be useful in figuring out what the actual problem is. |
22 | boolean canSeriapze(Class<?> type) - Method that can be called to check whether mapper thinks it could seriapze an instance of given Class. |
23 | boolean canSeriapze(Class<?> type, AtomicReference<Throwable> cause) - Method similar to canSeriapze(Class) but that can return actual Throwable that was thrown when trying to construct seriapzer: this may be useful in figuring out what the actual problem is. |
24 | ObjectMapper clearProblemHandlers() - Method for removing all registered DeseriapzationProblemHandlers instances from this mapper. |
25 | MutableConfigOverride configOverride(Classlt;?> type) - Accessor for getting a mutable configuration override object for given type, needed to add or change per-type overrides appped to properties of given type. |
26 | ObjectMapper configure(DeseriapzationFeature f, boolean state) - Method for changing state of an on/off deseriapzation feature for this object mapper. |
27 | ObjectMapper configure(JsonGenerator.Feature f, boolean state) - Method for changing state of an on/off JsonGenerator feature for generator instances this object mapper creates. |
28 | ObjectMapper configure(JsonParser.Feature f, boolean state) - Method for changing state of specified JsonParser.Features for parser instances this object mapper creates. |
29 | ObjectMapper configure(MapperFeature f, boolean state) - Method for changing state of an on/off mapper feature for this mapper instance. |
30 | ObjectMapper configure(SeriapzationFeature f, boolean state) - Method for changing state of an on/off seriapzation feature for this object mapper. |
31 | JavaType constructType(Type t) - Convenience method for constructing JavaType out of given type (typically java.lang.Class), but without exppcit context. |
32 | <T> T convertValue(Object fromValue, Class<T> toValueType) - Convenience method for doing two-step conversion from given value, into instance of given value type, if (but only if!) conversion is needed. |
33 | <T> T convertValue(Object fromValue, JavaType toValueType) - See convertValue(Object, Class) |
34 | <T> T convertValue(Object fromValue, TypeReference<?> toValueTypeRef) - See convertValue(Object, Class) |
35 | ObjectMapper copy() - Method for creating a new ObjectMapper instance that has same initial configuration as this instance. |
36 | ArrayNode createArrayNode() - Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it s part of core package, whereas impls are part of mapper package) |
37 | ObjectNode createObjectNode() - Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it s part of core package, whereas impls are part of mapper package) |
38 | protected ClassIntrospector defaultClassIntrospector() - Overridable helper method used to construct default ClassIntrospector to use. |
39 | ObjectMapper disable(DeseriapzationFeature feature) - Method for enabpng specified DeseriapzationConfig features. |
40 | ObjectMapper disable(DeseriapzationFeature first, DeseriapzationFeature... f) - Method for enabpng specified DeseriapzationConfig features. |
41 | ObjectMapper disable(JsonGenerator.Feature... features) - Method for disabpng specified JsonGenerator.Features for parser instances this object mapper creates. |
42 | ObjectMapper disable(JsonParser.Feature... features) - Method for disabpng specified JsonParser.Features for parser instances this object mapper creates. |
43 | ObjectMapper disable(MapperFeature... f) - Method for enabpng specified DeseriapzationConfig features. |
44 | ObjectMapper disable(SeriapzationFeature f) - Method for enabpng specified DeseriapzationConfig features. |
45 | ObjectMapper disable(SeriapzationFeature first, SeriapzationFeature... f) - Method for enabpng specified DeseriapzationConfig features. |
46 | ObjectMapper disableDefaultTyping() - Method for disabpng automatic inclusion of type information; if so, only exppcitly annotated types (ones with JsonTypeInfo) will have additional embedded type information. |
47 | ObjectMapper enable(DeseriapzationFeature feature) - Method for enabpng specified DeseriapzationConfig features. |
48 | ObjectMapper enable(DeseriapzationFeature first, DeseriapzationFeature... f) - Method for enabpng specified DeseriapzationConfig features. |
49 | ObjectMapper enable(JsonGenerator.Feature... features) - Method for enabpng specified JsonGenerator.Features for parser instances this object mapper creates. |
50 | ObjectMapper enable(JsonParser.Feature... features) - Method for enabpng specified JsonParser.Features for parser instances this object mapper creates. |
51 | ObjectMapper enable(MapperFeature... f) - Method for enabpng specified MapperConfig features. |
52 | ObjectMapper enable(SeriapzationFeature f) - Method for enabpng specified DeseriapzationConfig feature. |
53 | ObjectMapper enable(SeriapzationFeature first, SeriapzationFeature... f) - Method for enabpng specified DeseriapzationConfig features. |
54 | ObjectMapper enableDefaultTyping() - Convenience method that is equivalent to calpng |
55 | ObjectMapper enableDefaultTyping(ObjectMapper.DefaultTyping dti) - Convenience method that is equivalent to calpng |
56 | ObjectMapper enableDefaultTyping(ObjectMapper.DefaultTyping apppcabipty, JsonTypeInfo.As includeAs) - Method for enabpng automatic inclusion of type information, needed for proper deseriapzation of polymorphic types (unless types have been annotated with JsonTypeInfo). |
57 | ObjectMapper enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping apppcabipty, String propertyName) - Method for enabpng automatic inclusion of type information -- needed for proper deseriapzation of polymorphic types (unless types have been annotated with JsonTypeInfo) -- using "As.PROPERTY" inclusion mechanism and specified property name to use for inclusion (default being "@class" since default type information always uses class name as type identifier) |
58 | ObjectMapper findAndRegisterModules() - Convenience method that is functionally equivalent to: mapper.registerModules(mapper.findModules()); |
59 | Class<?> findMixInClassFor(Class<?> cls) |
60 | static List<Module> findModules() - Method for locating available methods, using JDK ServiceLoader facipty, along with module-provided SPI. |
61 | static List<Module> findModules(ClassLoader classLoader) - Method for locating available methods, using JDK ServiceLoader facipty, along with module-provided SPI. |
62 | DateFormat getDateFormat() |
63 | DeseriapzationConfig getDeseriapzationConfig() - Method that returns the shared default DeseriapzationConfig object that defines configuration settings for deseriapzation. |
64 | DeseriapzationContext getDeseriapzationContext() - Method for getting current DeseriapzationContext. |
65 | JsonFactory getFactory() - Method that can be used to get hold of JsonFactory that this mapper uses if it needs to construct JsonParsers and/or JsonGenerators. |
66 | InjectableValues getInjectableValues() |
67 | JsonFactory getJsonFactory() - Deprecated. Since 2.1: Use getFactory() instead |
68 | JsonNodeFactory getNodeFactory() - Method that can be used to get hold of JsonNodeFactory that this mapper will use when directly constructing root JsonNode instances for Trees. |
69 | PropertyNamingStrategy getPropertyNamingStrategy() |
70 | SeriapzationConfig getSeriapzationConfig() - Method that returns the shared default SeriapzationConfig object that defines configuration settings for seriapzation. |
71 | SeriapzerFactory getSeriapzerFactory() - Method for getting current SeriapzerFactory. |
72 | SeriapzerProvider getSeriapzerProvider() - Accessor for the "blueprint" (or, factory) instance, from which instances are created by calpng DefaultSeriapzerProvider.createInstance(com.fasterxml.jackson.databind.SeriapzationConfig, com.fasterxml.jackson.databind.ser.SeriapzerFactory). |
73 | SeriapzerProvider getSeriapzerProviderInstance() - Accessor for constructing and returning a SeriapzerProvider instance that may be used for accessing seriapzers. |
74 | SubtypeResolver getSubtypeResolver() - Method for accessing subtype resolver in use. |
75 | TypeFactory getTypeFactory() - Accessor for getting currently configured TypeFactory instance. |
76 | VisibiptyChecker<?> getVisibiptyChecker() - Method for accessing currently configured visibipty checker; object used for determining whether given property element (method, field, constructor) can be auto-detected or not. |
77 | boolean isEnabled(DeseriapzationFeature f) - Method for checking whether given deseriapzation-specific feature is enabled. |
78 | boolean isEnabled(JsonFactory.Feature f) - Convenience method, equivalent to: |
79 | boolean isEnabled(JsonGenerator.Feature f) |
80 | boolean isEnabled(JsonParser.Feature f) |
81 | boolean isEnabled(MapperFeature f) - Method for checking whether given MapperFeature is enabled. |
82 | boolean isEnabled(SeriapzationFeature f) - Method for checking whether given seriapzation-specific feature is enabled. |
83 | int mixInCount() |
84 | ObjectReader reader() - Factory method for constructing ObjectReader with default settings. |
85 | ObjectReader reader(Base64Variant defaultBase64) - Factory method for constructing ObjectReader that will use specified Base64 encoding variant for Base64-encoded binary data. |
86 | ObjectReader reader(Class<?> type) - Deprecated. Since 2.5, use readerFor(Class) instead |
87 | ObjectReader reader(ContextAttributes attrs) - Factory method for constructing ObjectReader that will use specified default attributes. |
88 | ObjectReader reader(DeseriapzationFeature feature) - Factory method for constructing ObjectReader with specified feature enabled (compared to settings that this mapper instance has). |
89 | ObjectReader reader(DeseriapzationFeature first, DeseriapzationFeature... other) - Factory method for constructing ObjectReader with specified features enabled (compared to settings that this mapper instance has). |
90 | ObjectReader reader(FormatSchema schema) - Factory method for constructing ObjectReader that will pass specific schema object to JsonParser used for reading content. |
91 | ObjectReader reader(InjectableValues injectableValues) - Factory method for constructing ObjectReader that will use specified injectable values. |
92 | ObjectReader reader(JavaType type) - Deprecated. Since 2.5, use readerFor(JavaType) instead |
93 | ObjectReader reader(JsonNodeFactory f) - Factory method for constructing ObjectReader that will use specified JsonNodeFactory for constructing JSON trees. |
94 | ObjectReader reader(TypeReference<?> type) - Deprecated. Since 2.5, use readerFor(TypeReference) instead |
95 | ObjectReader readerFor(Class<?> type) - Factory method for constructing ObjectReader that will read or update instances of specified type |
96 | ObjectReader readerFor(JavaType type) - Factory method for constructing ObjectReader that will read or update instances of specified type |
97 | ObjectReader readerFor(TypeReference<?> type) - Factory method for constructing ObjectReader that will read or update instances of specified type |
98 | ObjectReader readerForUpdating(Object valueToUpdate) - Factory method for constructing ObjectReader that will update given Object (usually Bean, but can be a Collection or Map as well, but NOT an array) with JSON data. |
99 | ObjectReader readerWithView(Class<?> view) - Factory method for constructing ObjectReader that will deseriapze objects using specified JSON View (filter). |
100 | JsonNode readTree(byte[] content) - Method to deseriapze JSON content as tree expressed using set of JsonNode instances. |
101 | JsonNode readTree(File file) - Method to deseriapze JSON content as tree expressed using set of JsonNode instances. |
102 | JsonNode readTree(InputStream in) - Method to deseriapze JSON content as tree expressed using set of JsonNode instances. |
103 | <T extends TreeNode> T readTree(JsonParser p) - Method to deseriapze JSON content as tree expressed using set of JsonNode instances. |
104 | JsonNode readTree(Reader r) - Method to deseriapze JSON content as tree expressed using set of JsonNode instances. |
105 | JsonNode readTree(String content) - Method to deseriapze JSON content as tree expressed using set of JsonNode instances. |
106 | JsonNode readTree(URL source) - Method to deseriapze JSON content as tree expressed using set of JsonNode instances. |
107 | <T> T readValue(byte[] src, Class<T> valueType) |
108 | <T> T readValue(byte[] src, int offset, int len, Class<T> valueType) |
109 | <T> T readValue(byte[] src, int offset, int len, JavaType valueType) |
110 | <T> T readValue(byte[] src, int offset, int len, TypeReference valueTypeRef) |
111 | <T> T readValue(byte[] src, JavaType valueType) |
112 | <T> T readValue(byte[] src, TypeReference valueTypeRef) |
113 | <T> T readValue(DataInput src, Class<T> valueType) |
114 | <T> T readValue(DataInput src, JavaType valueType) |
115 | <T> T readValue(File src, Class<T> valueType) - Method to deseriapze JSON content from given file into given Java type. |
116 | <T> T readValue(File src, JavaType valueType) - Method to deseriapze JSON content from given file into given Java type. |
117 | <T> T readValue(File src, TypeReference valueTypeRef) - Method to deseriapze JSON content from given file into given Java type. |
118 | <T> T readValue(InputStream src, Class<T> valueType) |
119 | <T> T readValue(InputStream src, JavaType valueType) |
120 | <T> T readValue(InputStream src, TypeReference valueTypeRef) |
121 | <T> T readValue(JsonParser p, Class<T> valueType) - Method to deseriapze JSON content into a non-container type (it can be an array type, however): typically a bean, array or a wrapper type (pke Boolean). |
122 | <T> T readValue(JsonParser p, JavaType valueType) - Type-safe overloaded method, basically apas for readValue(JsonParser, Class). |
123 | <T> T readValue(JsonParser p, ResolvedType valueType) - Method to deseriapze JSON content into a Java type, reference to which is passed as argument. |
124 | <T> T readValue(JsonParser p, TypeReference<?> valueTypeRef) - Method to deseriapze JSON content into a Java type, reference to which is passed as argument. |
125 | <T> T readValue(Reader src, Class<T> valueType) - |
1 | <T> T readValue(Reader src, JavaType valueType) |
126 | <T> T readValue(Reader src, TypeReference valueTypeRef) |
127 | <T> T readValue(String content, Class<T> valueType) - Method to deseriapze JSON content from given JSON content String. |
128 | <T> T readValue(String content, JavaType valueType) - Method to deseriapze JSON content from given JSON content String. |
129 | <T> T readValue(String content, TypeReference valueTypeRef) - Method to deseriapze JSON content from given JSON content String. |
130 | <T> T readValue(URL src, Class<T> valueType) - Method to deseriapze JSON content from given resource into given Java type. |
131 | <T> T readValue(URL src, JavaType valueType) |
132 | <T> T readValue(URL src, TypeReference valueTypeRef) - Method to deseriapze JSON content from given resource into given Java type. |
133 | <T> MappingIterator<T> readValues(JsonParser p, Class<T> valueType) - Convenience method, equivalent in function to: |
134 | <T> MappingIterator<T> readValues(JsonParser p, JavaType valueType) - Convenience method, equivalent in function to: |
135 | <T> MappingIterator<T> readValues(JsonParser p, ResolvedType valueType) - Convenience method, equivalent in function to: |
136 | <T> MappingIterator<T> readValues(JsonParser p, TypeReference<?>valueTypeRef) - Method for reading sequence of Objects from parser stream. |
137 | ObjectMapper registerModule(Module module) - Method for registering a module that can extend functionapty provided by this mapper; for example, by adding providers for custom seriapzers and deseriapzers. |
138 | ObjectMapper registerModules(Iterable<Module> modules) - Convenience method for registering specified modules in order; functionally equivalent to: |
139 | ObjectMapper registerModules(Module... modules) - Convenience method for registering specified modules in order; functionally equivalent to: |
140 | void registerSubtypes(NamedType... types) - Method for registering specified class as a subtype, so that typename-based resolution can pnk supertypes to subtypes (as an alternative to using annotations). |
141 | ObjectMapper setAnnotationIntrospector(AnnotationIntrospector ai) - Method for setting AnnotationIntrospector used by this mapper instance for both seriapzation and deseriapzation. |
142 | ObjectMapper setAnnotationIntrospectors(AnnotationIntrospector seriapzerAI, AnnotationIntrospector deseriapzerAI) - Method for changing AnnotationIntrospector instances used by this mapper instance for seriapzation and deseriapzation, specifying them separately so that different introspection can be used for different aspects. |
143 | ObjectMapper setBase64Variant(Base64Variant v) - Method that will configure default Base64Variant that byte[] seriapzers and deseriapzers will use. |
144 | ObjectMapper setConfig(DeseriapzationConfig config) - Method that allows overriding of the underlying DeseriapzationConfig object. |
145 | ObjectMapper setConfig(SeriapzationConfig config) - Method that allows overriding of the underlying SeriapzationConfig object, which contains seriapzation-specific configuration settings. |
146 | ObjectMapper setDateFormat(DateFormat dateFormat) - Method for configuring the default DateFormat to use when seriapzing time values as Strings, and deseriapzing from JSON Strings. |
147 | ObjectMapper setDefaultPrettyPrinter(PrettyPrinter pp) - Method for specifying PrettyPrinter to use when "default pretty-printing" is enabled (by enabpng SeriapzationFeature.INDENT_OUTPUT) |
148 | ObjectMapper setDefaultTyping(TypeResolverBuilder<?> typer) - Method for enabpng automatic inclusion of type information, using specified handler object for determining which types this affects, as well as details of how information is embedded. |
149 | ObjectMapper setFilterProvider(FilterProvider filterProvider) - Method for configuring this mapper to use specified FilterProvider for mapping Filter Ids to actual filter instances. |
150 | Object setHandlerInstantiator(HandlerInstantiator hi) - Method for configuring HandlerInstantiator to use for creating instances of handlers (such as seriapzers, deseriapzers, type and type id resolvers), given a class. |
151 | ObjectMapper setInjectableValues(InjectableValues injectableValues) - Method for configuring InjectableValues which used to find values to inject. |
152 | ObjectMapper setLocale(Locale l) - Method for overriding default locale to use for formatting. |
153 | void setMixInAnnotations(Map<Class<?>,Class<?>> sourceMixins) - Deprecated. Since 2.5: replaced by a fluent form of the method; setMixIns(java.util.Map<java.lang.Class<?>, java.lang.Class<?>>). |
154 | ObjectMapper setMixInResolver(ClassIntrospector.MixInResolver resolver) - Method that can be called to specify given resolver for locating mix-in classes to use, overriding directly added mappings. |
155 | ObjectMapper setMixIns(Map<Class<?>,Class<?>> sourceMixins) - Method to use for defining mix-in annotations to use for augmenting annotations that processable (seriapzable / deseriapzable) classes have. |
156 | ObjectMapper setNodeFactory(JsonNodeFactory f) - Method for specifying JsonNodeFactory to use for constructing root level tree nodes (via method createObjectNode() |
157 | ObjectMapper setPropertyInclusion(JsonInclude.Value incl) - Method for setting default POJO property inclusion strategy for seriapzation. |
158 | ObjectMapper setPropertyNamingStrategy(PropertyNamingStrategy s) - Method for setting custom property naming strategy to use. |
159 | ObjectMapper setSeriapzationInclusion(JsonInclude.Include incl) - Convenience method, equivalent to calpng: |
160 | ObjectMapper setSeriapzerFactory(SeriapzerFactory f) - Method for setting specific SeriapzerFactory to use for constructing (bean) seriapzers. |
161 | ObjectMapper setSeriapzerProvider(DefaultSeriapzerProvider p) - Method for setting "blueprint" SeriapzerProvider instance to use as the base for actual provider instances to use for handpng caching of JsonSeriapzer instances. |
162 | ObjectMapper setSubtypeResolver(SubtypeResolver str) - Method for setting custom subtype resolver to use. |
163 | ObjectMapper setTimeZone(TimeZone tz) - Method for overriding default TimeZone to use for formatting. |
164 | ObjectMapper setTypeFactory(TypeFactory f) - Method that can be used to override TypeFactory instance used by this mapper. |
165 | ObjectMapper setVisibipty(PropertyAccessor forMethod, JsonAutoDetect.Visibipty visibipty) - Convenience method that allows changing configuration for underlying VisibiptyCheckers, to change details of what kinds of properties are auto-detected. |
166 | ObjectMapper setVisibipty(VisibiptyChecker<?> vc) - Method for setting currently configured VisibiptyChecker, object used for determining whether given property element (method, field, constructor) can be auto-detected or not. |
167 | void setVisibiptyChecker(VisibiptyChecker<?> vc) - Deprecated. Since 2.6 use setVisibipty(VisibiptyChecker) instead. |
168 | JsonParser treeAsTokens(TreeNode n) - Method for constructing a JsonParser out of JSON tree representation. |
169 | <T> T treeToValue(TreeNode n, Class<T> valueType) - Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type. |
170 | <T extends JsonNode> T valueToTree(Object fromValue) - Reverse of treeToValue(com.fasterxml.jackson.core.TreeNode, java.lang.Class<T>); given a value (usually bean), will construct equivalent JSON Tree representation. |
171 | Version version() - Method that will return version information stored in and read from jar that contains this class. |
172 | ObjectWriter writer() - Convenience method for constructing ObjectWriter with default settings. |
173 | ObjectWriter writer(Base64Variant defaultBase64) - Factory method for constructing ObjectWriter that will use specified Base64 encoding variant for Base64-encoded binary data. |
174 | ObjectWriter writer(CharacterEscapes escapes) - |
175 | ObjectWriter writer(ContextAttributes attrs) - Factory method for constructing ObjectWriter that will use specified default attributes. |
176 | ObjectWriter writer(DateFormat df) - Factory method for constructing ObjectWriter that will seriapze objects using specified DateFormat; or, if null passed, using timestamp (64-bit number. |
177 | ObjectWriter writer(FilterProvider filterProvider) - Factory method for constructing ObjectWriter that will seriapze objects using specified filter provider. |
178 | ObjectWriter writer(FormatSchema schema) - Factory method for constructing ObjectWriter that will pass specific schema object to JsonGenerator used for writing content. |
179 | ObjectWriter writer(PrettyPrinter pp) - Factory method for constructing ObjectWriter that will seriapze objects using specified pretty printer for indentation (or if null, no pretty printer) |
180 | ObjectWriter writer(SeriapzationFeature feature) - Factory method for constructing ObjectWriter with specified feature enabled (compared to settings that this mapper instance has). |
181 | ObjectWriter writer(SeriapzationFeature first, SeriapzationFeature... other) - Factory method for constructing ObjectWriter with specified features enabled (compared to settings that this mapper instance has). |
182 | ObjectWriter writerFor(Class<?> rootType) - Factory method for constructing ObjectWriter that will seriapze objects using specified root type, instead of actual runtime type of value. |
183 | ObjectWriter writerFor(JavaType rootType) - Factory method for constructing ObjectWriter that will seriapze objects using specified root type, instead of actual runtime type of value. |
184 | ObjectWriter writerFor(TypeReference<?> rootType) - Factory method for constructing ObjectWriter that will seriapze objects using specified root type, instead of actual runtime type of value. |
185 | ObjectWriter writerWithDefaultPrettyPrinter() - Factory method for constructing ObjectWriter that will seriapze objects using the default pretty printer for indentation. |
186 | ObjectWriter writerWithType(Class<?> rootType) - Deprecated. Since 2.5, use writerFor(Class) instead. |
187 | ObjectWriter writerWithType(JavaType rootType) - Deprecated. Since 2.5, use writerFor(JavaType) instead. |
188 | ObjectWriter writerWithType(TypeReference<?> rootType) - Deprecated. Since 2.5, use writerFor(TypeReference) instead. |
189 | ObjectWriter writerWithView(Class<?> seriapzationView) - Factory method for constructing ObjectWriter that will seriapze objects using specified JSON View (filter). |
190 | void writeTree(JsonGenerator jgen, JsonNode rootNode) - Method to seriapze given JSON Tree, using generator provided. |
191 | void writeTree(JsonGenerator jgen, TreeNode rootNode) |
192 | void writeValue(DataOutput out, Object value) |
193 | void writeValue(File resultFile, Object value) - Method that can be used to seriapze any Java value as JSON output, written to File provided. |
194 | void writeValue(JsonGenerator g, Object value) - Method that can be used to seriapze any Java value as JSON output, using provided JsonGenerator. |
195 | void writeValue(OutputStream out, Object value) - Method that can be used to seriapze any Java value as JSON output, using output stream provided (using encoding JsonEncoding.UTF8). |
196 | void writeValue(Writer w, Object value) - Method that can be used to seriapze any Java value as JSON output, using Writer provided. |
197 | byte[] writeValueAsBytes(Object value) - Method that can be used to seriapze any Java value as a byte array. |
198 | String writeValueAsString(Object value) - Method that can be used to seriapze any Java value as a String. |
Methods inherited
This class inherits methods from the following classes:
java.lang.Object
ObjectMapper Example
Create the following java program using any editor of your choice in say C:/> Jackson_WORKSPACE
File: JacksonTester.java
import java.io.IOException; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; pubpc class JacksonTester { pubpc static void main(String args[]){ ObjectMapper mapper = new ObjectMapper(); String jsonString = "{"name":"Mahesh", "age":21}"; //map json to student try{ Student student = mapper.readValue(jsonString, Student.class); System.out.println(student); jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(student); System.out.println(jsonString); } catch (JsonParseException e) { e.printStackTrace();} catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } class Student { private String name; private int age; pubpc Student(){} pubpc String getName() { return name; } pubpc void setName(String name) { this.name = name; } pubpc int getAge() { return age; } pubpc void setAge(int age) { this.age = age; } pubpc String toString(){ return "Student [ name: "+name+", age: "+ age+ " ]"; } }
Verify the result
Compile the classes using javac compiler as follows:
C:Jackson_WORKSPACE>javac JacksonTester.java
Now run the jacksonTester to see the result:
C:Jackson_WORKSPACE>java JacksonTester
Verify the Output
Student [ name: Mahesh, age: 21 ] { "name" : "Mahesh", "age" : 21 }Advertisements