Class ObjectMapper

java.lang.Object
tools.jackson.databind.ObjectMapper
All Implemented Interfaces:
Serializable, tools.jackson.core.TreeCodec, tools.jackson.core.Versioned
Direct Known Subclasses:
JsonMapper

public class ObjectMapper extends Object implements tools.jackson.core.TreeCodec, tools.jackson.core.Versioned, Serializable
ObjectMapper provides functionality 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 functionality for performing conversions. In addition to directly reading and writing JSON (and with different underlying TokenStreamFactory configuration, other formats), it is also the mechanism for creating ObjectReaders and ObjectWriters which offer more advancing reading/writing functionality.

Construction of mapper instances proceeds either via no-arguments constructor (producing instance with default configuration); or through one of two build methods. First build method is the static builder() on exact type and second rebuild() method on an existing mapper. Former starts with default configuration (same as one that no-arguments constructor created mapper has), and latter starts with configuration of the mapper it is called on. In both cases, after configuration (including addition of JacksonModules) is complete, instance is created by calling MapperBuilder.build() method.

Mapper (and ObjectReaders, ObjectWriters it constructs) will use instances of JsonParser and JsonGenerator for implementing actual reading/writing of JSON. Note that although most read and write methods are exposed through this class, some of the functionality is only exposed via ObjectReader and ObjectWriter: specifically, reading/writing of longer sequences of values is only available through ObjectReader.readValues(InputStream) and ObjectWriter.writeValues(OutputStream).

Simplest usage is of form:

  final ObjectMapper mapper = new ObjectMapper(); // can use static singleton, inject: just make sure to reuse!
  MyValue value = new MyValue();
  // ... and configure
  File newState = new File("my-stuff.json");
  mapper.writeValue(newState, value); // writes JSON serialization of MyValue instance
  // or, read
  MyValue older = mapper.readValue(new File("my-older-stuff.json"), MyValue.class);

  // Or if you prefer JSON Tree representation:
  JsonNode root = mapper.readTree(newState);
  // and find values by, for example, using a JsonPointer expression:
  int age = root.at("/personal/age").getValueAsInt();

Mapper instances are fully thread-safe as of Jackson 3.0.

Note on caching: root-level deserializers are always cached, and accessed using full (generics-aware) type information. This is different from caching of referenced types, which is more limited and is done only for a subset of all deserializer types. The main reason for difference is that at root-level there is no incoming reference (and hence no referencing property, no referral information or annotations to produce differing deserializers), and that the performance impact greatest at root level (since it'll essentially cache the full graph of deserializers involved).

See Also:
  • Field Details

    • _streamFactory

      protected final tools.jackson.core.TokenStreamFactory _streamFactory
      Factory used to create JsonParser and JsonGenerator instances as necessary.
    • _typeFactory

      protected final TypeFactory _typeFactory
      Specific factory used for creating JavaType instances; needed to allow modules to add more custom type handling (mostly to support types of non-Java JVM languages)
    • _injectableValues

      protected final InjectableValues _injectableValues
      Provider for values to inject in deserialized POJOs.
    • _serializationContexts

      protected final SerializationContexts _serializationContexts
      Factory used for constructing per-call SerializationContexts.

      Note: while serializers are only exposed SerializationContext, mappers and readers need to access additional API defined by SerializationContextExt

    • _serializationConfig

      protected final SerializationConfig _serializationConfig
      Configuration object that defines basic global settings for the serialization process
    • _deserializationContexts

      protected final DeserializationContexts _deserializationContexts
      Factory used for constructing per-call DeserializationContexts.
    • _deserializationConfig

      protected final DeserializationConfig _deserializationConfig
      Configuration object that defines basic global settings for the serialization process
    • _rootDeserializers

      protected final ConcurrentHashMap<JavaType,ValueDeserializer<Object>> _rootDeserializers
      We will use a separate main-level Map for keeping track of root-level deserializers. This is where most successful cache lookups get resolved. Map will contain resolvers for all kinds of types, including container types: this is different from the component cache which will only cache bean deserializers.

      Given that we don't expect much concurrency for additions (should very quickly converge to zero after startup), let's explicitly define a low concurrency setting.

      These may are either "raw" deserializers (when no type information is needed for base type), or type-wrapped deserializers (if it is needed)

    • _savedBuilderState

      protected final MapperBuilderState _savedBuilderState
      Minimal state retained to allow both re-building (by creating new builder) and JDK serialization of this mapper.
      Since:
      3.0
  • Constructor Details

    • ObjectMapper

      public ObjectMapper()
      Default constructor, which will construct the default JSON-handling TokenStreamFactory as necessary and all other unmodified default settings, and no additional registered modules.
    • ObjectMapper

      public ObjectMapper(tools.jackson.core.TokenStreamFactory streamFactory)
      Constructs instance that uses specified TokenStreamFactory for constructing necessary JsonParsers and/or JsonGenerators, but without registering additional modules.
    • ObjectMapper

      protected ObjectMapper(MapperBuilder<?,?> builder)
      Constructor usually called either by MapperBuilder.build() or by sub-class constructor: will get all the settings through passed-in builder, including registration of any modules added to builder.
  • Method Details

    • rebuild

      public <M extends ObjectMapper, B extends MapperBuilder<M, B>> MapperBuilder<M,B> rebuild()
      Method for creating a new MapperBuilder for constructing differently configured ObjectMapper instance, starting with current configuration including base settings and registered modules.
      Since:
      3.0
    • writeReplace

      protected Object writeReplace()
    • readResolve

      protected Object readResolve()
    • version

      public tools.jackson.core.Version version()
      Method that will return version information stored in and read from jar that contains this class.
      Specified by:
      version in interface tools.jackson.core.Versioned
    • serializationConfig

      public SerializationConfig serializationConfig()
      Accessor for internal configuration object that contains settings for serialization operations (writeValue(...) methods)
      NOTE: Not to be used by application code; needed by some tests
    • deserializationConfig

      public DeserializationConfig deserializationConfig()
      Accessor for internal configuration object that contains settings for deserialization operations (readValue(...) methods)
      NOTE: Not to be used by application code; needed by some tests
    • tokenStreamFactory

      public tools.jackson.core.TokenStreamFactory tokenStreamFactory()
      Method that can be used to get hold of TokenStreamFactory that this mapper uses if it needs to construct JsonParsers and/or JsonGenerators.

      WARNING: note that all ObjectReader and ObjectWriter instances created by this mapper usually share the same configured TokenStreamFactory, so changes to its configuration will "leak". To avoid such observed changes you should always use "with()" and "without()" method of ObjectReader and ObjectWriter for changing StreamReadFeature and StreamWriteFeature settings to use on per-call basis.

      Returns:
      TokenStreamFactory that this mapper uses when it needs to construct Json parser and generators
      Since:
      3.0
    • getNodeFactory

      public 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.

      Note: this is just a shortcut for calling

         getDeserializationConfig().getNodeFactory()
      
    • getInjectableValues

      public InjectableValues getInjectableValues()
    • getTypeFactory

      public TypeFactory getTypeFactory()
      Accessor for getting currently configured TypeFactory instance.
    • constructType

      public JavaType constructType(Type type)
      Convenience method for constructing JavaType out of given type (typically java.lang.Class), but without explicit context.
    • constructType

      public JavaType constructType(tools.jackson.core.type.TypeReference<?> typeReference)
      Convenience method for constructing JavaType out of given type reference.
    • isEnabled

      public boolean isEnabled(tools.jackson.core.TokenStreamFactory.Feature f)
    • isEnabled

      public boolean isEnabled(tools.jackson.core.StreamReadFeature f)
    • isEnabled

      public boolean isEnabled(tools.jackson.core.StreamWriteFeature f)
    • isEnabled

      public boolean isEnabled(MapperFeature f)
      Method for checking whether given MapperFeature is enabled.
    • isEnabled

      public boolean isEnabled(DeserializationFeature f)
      Method for checking whether given deserialization-specific feature is enabled.
    • isEnabled

      public boolean isEnabled(SerializationFeature f)
      Method for checking whether given serialization-specific feature is enabled.
    • getRegisteredModules

      public Collection<JacksonModule> getRegisteredModules()
      Method that may be used to find out JacksonModules that were registered when creating this mapper (if any).
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(File src) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,java.io.File).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(Path src) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,Path).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(URL src) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,java.net.URL).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(InputStream in) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,InputStream).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(Reader r) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,Reader).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(byte[] content) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,byte[]).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(byte[] content, int offset, int len) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,byte[],int,int).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(String content) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,String).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(char[] content) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,char[]).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(char[] content, int offset, int len) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,char[],int,int).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createParser

      public tools.jackson.core.JsonParser createParser(DataInput content) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonParser that is properly wired to allow callbacks for deserialization: basically constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,DataInput).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createNonBlockingByteArrayParser

      public tools.jackson.core.JsonParser createNonBlockingByteArrayParser() throws tools.jackson.core.JacksonException
      Factory method for constructing non-blocking JsonParser that is properly wired to allow configuration access (and, if relevant for parser, callbacks): essentially constructs a ObjectReadContext and then calls TokenStreamFactory.createParser(ObjectReadContext,DataInput).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createGenerator

      public tools.jackson.core.JsonGenerator createGenerator(OutputStream out) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createGenerator

      public tools.jackson.core.JsonGenerator createGenerator(OutputStream out, tools.jackson.core.JsonEncoding enc) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory.createGenerator(ObjectWriteContext,OutputStream,JsonEncoding).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createGenerator

      public tools.jackson.core.JsonGenerator createGenerator(Writer w) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory.createGenerator(ObjectWriteContext,Writer).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createGenerator

      public tools.jackson.core.JsonGenerator createGenerator(File f, tools.jackson.core.JsonEncoding enc) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory.createGenerator(ObjectWriteContext,File,JsonEncoding).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createGenerator

      public tools.jackson.core.JsonGenerator createGenerator(Path path, tools.jackson.core.JsonEncoding enc) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory.createGenerator(ObjectWriteContext,Path,JsonEncoding).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createGenerator

      public tools.jackson.core.JsonGenerator createGenerator(DataOutput out) throws tools.jackson.core.JacksonException
      Factory method for constructing JsonGenerator that is properly wired to allow callbacks for serialization: basically constructs a ObjectWriteContext and then calls TokenStreamFactory.createGenerator(ObjectWriteContext,DataOutput).
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • createObjectNode

      public ObjectNode createObjectNode()

      Note: return type is co-variant, as basic TreeCodec abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)

      Specified by:
      createObjectNode in interface tools.jackson.core.TreeCodec
    • createArrayNode

      public ArrayNode createArrayNode()

      Note: return type is co-variant, as basic TreeCodec abstraction cannot refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)

      Specified by:
      createArrayNode in interface tools.jackson.core.TreeCodec
    • booleanNode

      public JsonNode booleanNode(boolean b)
      Specified by:
      booleanNode in interface tools.jackson.core.TreeCodec
    • stringNode

      public JsonNode stringNode(String text)
      Specified by:
      stringNode in interface tools.jackson.core.TreeCodec
    • missingNode

      public JsonNode missingNode()
      Specified by:
      missingNode in interface tools.jackson.core.TreeCodec
    • nullNode

      public JsonNode nullNode()
      Specified by:
      nullNode in interface tools.jackson.core.TreeCodec
    • treeAsTokens

      public tools.jackson.core.JsonParser treeAsTokens(tools.jackson.core.TreeNode n)
      Method for constructing a JsonParser out of JSON tree representation.
      Specified by:
      treeAsTokens in interface tools.jackson.core.TreeCodec
      Parameters:
      n - Root node of the tree that resulting parser will read from
    • readTree

      public JsonNode readTree(tools.jackson.core.JsonParser p) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content as a tree JsonNode. Returns JsonNode that represents the root of the resulting tree, if there was content to read, or null if no more content is accessible via passed JsonParser.

      NOTE! Behavior with end-of-input (no more content) differs between this readTree method, and all other methods that take input source: latter will return "missing node", NOT null

      Specified by:
      readTree in interface tools.jackson.core.TreeCodec
      Returns:
      a JsonNode, if valid JSON content found; null if input has no content to bind -- note, however, that if JSON null token is found, it will be represented as a non-null JsonNode (one that returns true for JsonNode.isNull()
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      tools.jackson.core.JacksonException
    • writeTree

      public void writeTree(tools.jackson.core.JsonGenerator g, tools.jackson.core.TreeNode rootNode) throws tools.jackson.core.JacksonException
      Specified by:
      writeTree in interface tools.jackson.core.TreeCodec
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(tools.jackson.core.JsonParser p, Class<T> valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content into a non-container type (it can be an array type, however): typically a bean, array or a wrapper type (like Boolean).

      Note: this method should NOT be used if the result type is a container (Collection or Map. The reason is that due to type erasure, key and value types cannot be introspected when using this method.

      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(tools.jackson.core.JsonParser p, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content into a Java type, reference to which is passed as argument. Type is passed using so-called "super type token" (see ) and specifically needs to be used if the root type is a parameterized (generic) container type.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public final <T> T readValue(tools.jackson.core.JsonParser p, tools.jackson.core.type.ResolvedType valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content into a Java type, reference to which is passed as argument. Type is passed using Jackson specific type; instance of which can be constructed using TypeFactory.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(tools.jackson.core.JsonParser p, JavaType valueType) throws tools.jackson.core.JacksonException
      Type-safe overloaded method, basically alias for readValue(JsonParser, Class).
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValues

      public <T> MappingIterator<T> readValues(tools.jackson.core.JsonParser p, JavaType valueType) throws tools.jackson.core.JacksonException
      Convenience method, equivalent in function to:
         readerFor(valueType).readValues(p);
      

      Method for reading sequence of Objects from parser stream. Sequence can be either root-level "unwrapped" sequence (without surrounding JSON array), or a sequence contained in a JSON Array. In either case JsonParser MUST point to the first token of the first element, OR not point to any token (in which case it is advanced to the next token). This means, specifically, that for wrapped sequences, parser MUST NOT point to the surrounding START_ARRAY (one that contains values to read) but rather to the token following it which is the first token of the first value to read.

      Note that ObjectReader has more complete set of variants.

      Throws:
      tools.jackson.core.JacksonException
    • readValues

      public <T> MappingIterator<T> readValues(tools.jackson.core.JsonParser p, Class<T> valueType) throws tools.jackson.core.JacksonException
      Convenience method, equivalent in function to:
         readerFor(valueType).readValues(p);
      

      Type-safe overload of readValues(JsonParser, JavaType).

      Throws:
      tools.jackson.core.JacksonException
    • readValues

      public <T> MappingIterator<T> readValues(tools.jackson.core.JsonParser p, tools.jackson.core.type.TypeReference<T> valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readTree

      public JsonNode readTree(InputStream in) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content as tree expressed using set of JsonNode instances. Returns root of the resulting tree (where root can consist of just a single node if the current event is a value event, not container).

      If a low-level I/O problem (missing input, network error) occurs, a IOException will be thrown. If a parsing problem occurs (invalid JSON), StreamReadException will be thrown. If no content is found from input (end-of-input), Java null will be returned.

      Parameters:
      in - Input stream used to read JSON content for building the JSON tree.
      Returns:
      a JsonNode, if valid JSON content found; null if input has no content to bind -- note, however, that if JSON null token is found, it will be represented as a non-null JsonNode (one that returns true for JsonNode.isNull()
      Throws:
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      tools.jackson.core.JacksonException
    • readTree

      public JsonNode readTree(Reader r) throws tools.jackson.core.JacksonException
      Same as readTree(InputStream) except content accessed through passed-in Reader
      Throws:
      tools.jackson.core.JacksonException
    • readTree

      public JsonNode readTree(String content) throws tools.jackson.core.JacksonException
      Same as readTree(InputStream) except content read from passed-in String
      Throws:
      tools.jackson.core.JacksonException
    • readTree

      public JsonNode readTree(byte[] content) throws tools.jackson.core.JacksonException
      Same as readTree(InputStream) except content read from passed-in byte array.
      Throws:
      tools.jackson.core.JacksonException
    • readTree

      public JsonNode readTree(byte[] content, int offset, int len) throws tools.jackson.core.JacksonException
      Same as readTree(InputStream) except content read from passed-in byte array.
      Throws:
      tools.jackson.core.JacksonException
    • readTree

      public JsonNode readTree(File file) throws tools.jackson.core.JacksonException
      Same as readTree(InputStream) except content read from passed-in File.
      Throws:
      tools.jackson.core.JacksonException
    • readTree

      public JsonNode readTree(Path path) throws tools.jackson.core.JacksonException
      Same as readTree(InputStream) except content read from passed-in Path.
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • readTree

      public JsonNode readTree(URL src) throws tools.jackson.core.JacksonException
      Same as readTree(InputStream) except content read from passed-in URL.

      NOTE: handling of URL is delegated to TokenStreamFactory.createParser(ObjectReadContext, java.net.URL)s and usually simply calls URL.openStream(), meaning no special handling is done. If different HTTP connection options are needed you will need to create InputStream separately.

      Throws:
      tools.jackson.core.JacksonException
    • writeValue

      public void writeValue(tools.jackson.core.JsonGenerator g, Object value) throws tools.jackson.core.JacksonException
      Method that can be used to serialize any Java value as JSON output, using provided JsonGenerator.
      Throws:
      tools.jackson.core.JacksonException
    • treeToValue

      public <T> T treeToValue(tools.jackson.core.TreeNode n, Class<T> valueType) throws tools.jackson.core.JacksonException
      Convenience conversion method that will bind data given JSON tree contains into specific value (usually bean) type.

      Functionally equivalent to:

         objectMapper.convertValue(n, valueClass);
      
      Throws:
      tools.jackson.core.JacksonException
    • treeToValue

      public <T> T treeToValue(tools.jackson.core.TreeNode n, JavaType valueType) throws tools.jackson.core.JacksonException
      Same as treeToValue(TreeNode, Class) but target type specified using fully resolved JavaType.
      Throws:
      tools.jackson.core.JacksonException
    • treeToValue

      public <T> T treeToValue(tools.jackson.core.TreeNode n, tools.jackson.core.type.TypeReference<T> toValueTypeRef) throws tools.jackson.core.JacksonException
      Same as treeToValue(TreeNode, JavaType) but target type specified using fully resolved TypeReference.
      Throws:
      tools.jackson.core.JacksonException
    • valueToTree

      public <T extends JsonNode> T valueToTree(Object fromValue) throws tools.jackson.core.JacksonException
      Method that is reverse of treeToValue(tools.jackson.core.TreeNode, java.lang.Class<T>): it will convert given Java value (usually bean) into its equivalent Tree model JsonNode representation. Functionally similar to serializing value into token stream and parsing that stream back as tree model node, but more efficient as TokenBuffer is used to contain the intermediate representation instead of fully serialized contents.

      NOTE: while results are usually identical to that of serialization followed by deserialization, this is not always the case. In some cases serialization into intermediate representation will retain encapsulation of things like raw value (RawValue) or basic node identity (JsonNode). If so, result is a valid tree, but values are not re-constructed through actual format representation. So if transformation requires actual materialization of encoded content, it will be necessary to do actual serialization.

      Type Parameters:
      T - Actual node type; usually either basic JsonNode or ObjectNode
      Parameters:
      fromValue - Java value to convert
      Returns:
      (non-null) Root node of the resulting content tree: in case of null value node for which JsonNode.isNull() returns true.
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(File src, Class<T> valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given file into given Java type.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(File src, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given file into given Java type.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(File src, JavaType valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given file into given Java type.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(Path src, Class<T> valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given path into given Java type.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
      Since:
      3.0
    • readValue

      public <T> T readValue(Path src, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given path into given Java type.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
      Since:
      3.0
    • readValue

      public <T> T readValue(Path src, JavaType valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given path into given Java type.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
      Since:
      3.0
    • readValue

      public <T> T readValue(URL src, Class<T> valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given resource into given Java type.

      NOTE: handling of URL is delegated to TokenStreamFactory.createParser(ObjectReadContext, java.net.URL) and usually simply calls URL.openStream(), meaning no special handling is done. If different HTTP connection options are needed you will need to create InputStream separately.

      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(URL src, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Same as readValue(java.net.URL, Class) except that target specified by TypeReference.
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(URL src, JavaType valueType) throws tools.jackson.core.JacksonException
      Same as readValue(java.net.URL, Class) except that target specified by JavaType.
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(String content, Class<T> valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given JSON content String.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(String content, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given JSON content String.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(String content, JavaType valueType) throws tools.jackson.core.JacksonException
      Method to deserialize JSON content from given JSON content String.
      Throws:
      tools.jackson.core.exc.JacksonIOException - if a low-level I/O problem (unexpected end-of-input, network error) occurs (passed through as-is without additional wrapping -- note that this is one case where DeserializationFeature.WRAP_EXCEPTIONS does NOT result in wrapping of exception even if enabled)
      tools.jackson.core.exc.StreamReadException - if underlying input contains invalid content of type JsonParser supports (JSON for default case)
      DatabindException - if the input JSON structure does not match structure expected for result type (or has other mismatch issues)
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(Reader src, Class<T> valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(Reader src, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(Reader src, JavaType valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(InputStream src, Class<T> valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(InputStream src, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(InputStream src, JavaType valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(byte[] content, Class<T> valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(byte[] content, int offset, int len, Class<T> valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(byte[] content, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(byte[] content, int offset, int len, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(byte[] content, JavaType valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(byte[] content, int offset, int len, JavaType valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(DataInput src, Class<T> valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(DataInput src, JavaType valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • readValue

      public <T> T readValue(DataInput src, tools.jackson.core.type.TypeReference<T> valueTypeRef) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • writeValue

      public void writeValue(File file, Object value) throws tools.jackson.core.JacksonException
      Method that can be used to serialize any Java value as JSON output, written to File provided.
      Throws:
      tools.jackson.core.JacksonException
    • writeValue

      public void writeValue(Path path, Object value) throws tools.jackson.core.JacksonException
      Method that can be used to serialize any Java value as JSON output, written to Path provided.
      Throws:
      tools.jackson.core.JacksonException
      Since:
      3.0
    • writeValue

      public void writeValue(OutputStream out, Object value) throws tools.jackson.core.JacksonException
      Method that can be used to serialize any Java value as JSON output, using output stream provided (using encoding JsonEncoding.UTF8).

      Note: method does not close the underlying stream explicitly here; however, TokenStreamFactory this mapper uses may choose to close the stream depending on its settings (by default, it will try to close it when JsonGenerator we construct is closed).

      Throws:
      tools.jackson.core.JacksonException
    • writeValue

      public void writeValue(DataOutput out, Object value) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • writeValue

      public void writeValue(Writer w, Object value) throws tools.jackson.core.JacksonException
      Method that can be used to serialize any Java value as JSON output, using Writer provided.

      Note: method does not close the underlying stream explicitly here; however, TokenStreamFactory this mapper uses may choose to close the stream depending on its settings (by default, it will try to close it when JsonGenerator we construct is closed).

      Throws:
      tools.jackson.core.JacksonException
    • writeValueAsString

      public String writeValueAsString(Object value) throws tools.jackson.core.JacksonException
      Method that can be used to serialize any Java value as a String. Functionally equivalent to calling writeValue(Writer,Object) with StringWriter and constructing String, but more efficient.
      Throws:
      tools.jackson.core.JacksonException
    • writeValueAsBytes

      public byte[] writeValueAsBytes(Object value) throws tools.jackson.core.JacksonException
      Method that can be used to serialize any Java value as a byte array. Functionally equivalent to calling writeValue(Writer,Object) with ByteArrayOutputStream and getting bytes, but more efficient. Encoding used will be UTF-8.
      Throws:
      tools.jackson.core.JacksonException
    • _configAndWriteValue

      protected final void _configAndWriteValue(SerializationContextExt prov, tools.jackson.core.JsonGenerator g, Object value) throws tools.jackson.core.JacksonException
      Method called to configure the generator as necessary and then call write functionality
      Throws:
      tools.jackson.core.JacksonException
    • _writeCloseableValue

      protected final void _writeCloseableValue(tools.jackson.core.JsonGenerator g, Object value, SerializationConfig cfg) throws tools.jackson.core.JacksonException
      Helper method used when value to serialize is Closeable and its close() method is to be called right after serialization has been called
      Throws:
      tools.jackson.core.JacksonException
    • writer

      public ObjectWriter writer()
      Convenience method for constructing ObjectWriter with default settings.
    • writer

      public ObjectWriter writer(SerializationFeature feature)
      Factory method for constructing ObjectWriter with specified feature enabled (compared to settings that this mapper instance has).
    • writer

      public ObjectWriter writer(SerializationFeature first, SerializationFeature... other)
      Factory method for constructing ObjectWriter with specified features enabled (compared to settings that this mapper instance has).
    • writer

      public ObjectWriter writer(DateFormat df)
      Factory method for constructing ObjectWriter that will serialize objects using specified DateFormat; or, if null passed, using timestamp (64-bit number.
    • writerWithView

      public ObjectWriter writerWithView(Class<?> serializationView)
      Factory method for constructing ObjectWriter that will serialize objects using specified JSON View (filter).
    • writerFor

      public ObjectWriter writerFor(Class<?> rootType)
      Factory method for constructing ObjectWriter that will serialize objects using specified root type, instead of actual runtime type of value. Type must be a super-type of runtime type.

      Main reason for using this method is performance, as writer is able to pre-fetch serializer to use before write, and if writer is used more than once this avoids addition per-value serializer lookups.

    • writerFor

      public ObjectWriter writerFor(tools.jackson.core.type.TypeReference<?> rootType)
      Factory method for constructing ObjectWriter that will serialize objects using specified root type, instead of actual runtime type of value. Type must be a super-type of runtime type.

      Main reason for using this method is performance, as writer is able to pre-fetch serializer to use before write, and if writer is used more than once this avoids addition per-value serializer lookups.

    • writerFor

      public ObjectWriter writerFor(JavaType rootType)
      Factory method for constructing ObjectWriter that will serialize objects using specified root type, instead of actual runtime type of value. Type must be a super-type of runtime type.

      Main reason for using this method is performance, as writer is able to pre-fetch serializer to use before write, and if writer is used more than once this avoids addition per-value serializer lookups.

    • writerWithDefaultPrettyPrinter

      public ObjectWriter writerWithDefaultPrettyPrinter()
      Factory method for constructing ObjectWriter that will serialize objects using the default pretty printer for indentation
    • writer

      public ObjectWriter writer(FilterProvider filterProvider)
      Factory method for constructing ObjectWriter that will serialize objects using specified filter provider.
    • writer

      public ObjectWriter writer(tools.jackson.core.FormatSchema schema)
      Factory method for constructing ObjectWriter that will pass specific schema object to JsonGenerator used for writing content.
      Parameters:
      schema - Schema to pass to generator
    • writer

      public ObjectWriter writer(tools.jackson.core.Base64Variant defaultBase64)
      Factory method for constructing ObjectWriter that will use specified Base64 encoding variant for Base64-encoded binary data.
    • writer

      public ObjectWriter writer(tools.jackson.core.io.CharacterEscapes escapes)
      Factory method for constructing ObjectReader that will use specified character escaping details for output.
    • writer

      public ObjectWriter writer(ContextAttributes attrs)
      Factory method for constructing ObjectWriter that will use specified default attributes.
    • reader

      public ObjectReader reader()
      Factory method for constructing ObjectReader with default settings. Note that the resulting instance is NOT usable as is, without defining expected value type.
    • reader

      public ObjectReader reader(DeserializationFeature feature)
      Factory method for constructing ObjectReader with specified feature enabled (compared to settings that this mapper instance has). Note that the resulting instance is NOT usable as is, without defining expected value type.
    • reader

      Factory method for constructing ObjectReader with specified features enabled (compared to settings that this mapper instance has). Note that the resulting instance is NOT usable as is, without defining expected value type.
    • readerForUpdating

      public 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. Deserialization occurs normally except that the root-level value in JSON is not used for instantiating a new object; instead give updateable object is used as root. Runtime type of value object is used for locating deserializer, unless overridden by other factory methods of ObjectReader
    • readerFor

      public ObjectReader readerFor(JavaType type)
      Factory method for constructing ObjectReader that will read or update instances of specified type
    • readerFor

      public ObjectReader readerFor(Class<?> type)
      Factory method for constructing ObjectReader that will read or update instances of specified type
    • readerFor

      public ObjectReader readerFor(tools.jackson.core.type.TypeReference<?> typeRef)
      Factory method for constructing ObjectReader that will read or update instances of specified type
    • readerForArrayOf

      public ObjectReader readerForArrayOf(Class<?> type)
      Factory method for constructing ObjectReader that will read values of a type List<type>. Functionally same as:
          readerFor(type[].class);
      
    • readerForListOf

      public ObjectReader readerForListOf(Class<?> type)
      Factory method for constructing ObjectReader that will read or update instances of a type List<type>. Functionally same as:
          readerFor(new TypeReference<List<type>>() { });
      
    • readerForMapOf

      public ObjectReader readerForMapOf(Class<?> type)
      Factory method for constructing ObjectReader that will read or update instances of a type Map<String, type> Functionally same as:
          readerFor(new TypeReference<Map<String, type>>() { });
      
      Since:
      2.11
    • reader

      public ObjectReader reader(JsonNodeFactory nodeFactory)
      Factory method for constructing ObjectReader that will use specified JsonNodeFactory for constructing JSON trees.
    • reader

      public ObjectReader reader(tools.jackson.core.FormatSchema schema)
      Factory method for constructing ObjectReader that will pass specific schema object to JsonParser used for reading content.
      Parameters:
      schema - Schema to pass to parser
    • reader

      public ObjectReader reader(InjectableValues injectableValues)
      Factory method for constructing ObjectReader that will use specified injectable values.
      Parameters:
      injectableValues - Injectable values to use
    • readerWithView

      public ObjectReader readerWithView(Class<?> view)
      Factory method for constructing ObjectReader that will deserialize objects using specified JSON View (filter).
    • reader

      public ObjectReader reader(tools.jackson.core.Base64Variant defaultBase64)
      Factory method for constructing ObjectReader that will use specified Base64 encoding variant for Base64-encoded binary data.
    • reader

      public ObjectReader reader(ContextAttributes attrs)
      Factory method for constructing ObjectReader that will use specified default attributes.
    • convertValue

      public <T> T convertValue(Object fromValue, Class<T> toValueType) throws IllegalArgumentException
      Convenience method for doing two-step conversion from given value, into instance of given value type, by writing value into temporary buffer and reading from the buffer into specified target type.

      This method is functionally similar to first serializing given value into JSON, and then binding JSON data into value of given type, but should be more efficient since full serialization does not (need to) occur. However, same converters (serializers, deserializers) will be used as for data binding, meaning same object mapper configuration works.

      Note that behavior changed slightly between Jackson 2.9 and 2.10 so that whereas earlier some optimizations were used to avoid write/read cycle in case input was of target type, from 2.10 onwards full processing is always performed. See databind#2220 for full details of the change.

      Further note that it is possible that in some cases behavior does differ from full serialize-then-deserialize cycle: in most case differences are unintentional (that is, flaws to fix) and should be reported, but the behavior is not guaranteed to be 100% the same: the goal is to allow efficient value conversions for structurally compatible Objects, according to standard Jackson configuration.

      Further note that this functionality is not designed to support "advanced" use cases, such as conversion of polymorphic values, or cases where Object Identity is used.

      Throws:
      IllegalArgumentException - If conversion fails due to incompatible type; if so, root cause will contain underlying checked exception data binding functionality threw
    • convertValue

      public <T> T convertValue(Object fromValue, tools.jackson.core.type.TypeReference<T> toValueTypeRef) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • convertValue

      public <T> T convertValue(Object fromValue, JavaType toValueType) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • _convert

      protected Object _convert(Object fromValue, JavaType toValueType) throws tools.jackson.core.JacksonException
      Actual conversion implementation: instead of using existing read and write methods, much of code is inlined. Reason for this is that we must avoid root value wrapping/unwrapping both for efficiency and for correctness. If root value wrapping/unwrapping is actually desired, caller must use explicit writeValue and readValue methods.
      Throws:
      tools.jackson.core.JacksonException
    • updateValue

      public <T> T updateValue(T valueToUpdate, Object overrides) throws tools.jackson.core.JacksonException
      Convenience method similar to convertValue(Object, JavaType) but one in which

      Implementation is approximately as follows:

      1. Serialize `updateWithValue` into TokenBuffer
      2. Construct ObjectReader with `valueToUpdate` (using readerForUpdating(Object))
      3. Construct JsonParser (using TokenBuffer.asParser(ObjectReadContext))
      4. Update using ObjectReader.readValue(JsonParser).
      5. Return `valueToUpdate`

      Note that update is "shallow" in that only first level of properties (or, immediate contents of container to update) are modified, unless properties themselves indicate that merging should be applied for contents. Such merging can be specified using annotations (see JsonMerge) as well as using "config overrides" (see MapperBuilder.withConfigOverride(java.lang.Class<?>, java.util.function.Consumer<tools.jackson.databind.cfg.MutableConfigOverride>) and MapperBuilder.defaultMergeable(java.lang.Boolean)).

      Parameters:
      valueToUpdate - Object to update
      overrides - Object to conceptually serialize and merge into value to update; can be thought of as a provider for overrides to apply.
      Returns:
      Either the first argument (`valueToUpdate`), if it is mutable; or a result of creating new instance that is result of "merging" values (for example, "updating" a Java array will create a new array)
      Throws:
      tools.jackson.core.JacksonException - if there are structural incompatibilities that prevent update.
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visitor)
      Method for visiting type hierarchy for given type, using specified visitor.

      This method can be used for things like generating JSON Schema instance for specified type.

      Parameters:
      type - Type to generate schema for (possibly with generic signature)
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(tools.jackson.core.type.TypeReference<?> typeRef, JsonFormatVisitorWrapper visitor)
    • acceptJsonFormatVisitor

      public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor)
      Method for visiting type hierarchy for given type, using specified visitor. Visitation uses Serializer hierarchy and related properties

      This method can be used for things like generating JSON Schema instance for specified type.

      Parameters:
      type - Type to generate schema for (possibly with generic signature)
    • clearCaches

      public void clearCaches()
      Method that will clear all caches this mapper owns.

      This method should not be needed in normal operation, but may be useful to avoid class-loader memory leaks when reloading applications.

      Since:
      2.19
    • _serializationContext

      protected SerializationContextExt _serializationContext(SerializationConfig config)
      Overridable helper method used for constructing SerializationContext to use for serialization.
    • _serializationContext

      public SerializationContextExt _serializationContext()
    • _readValue

      protected Object _readValue(DeserializationContextExt ctxt, tools.jackson.core.JsonParser p, JavaType valueType) throws tools.jackson.core.JacksonException
      Actual implementation of value reading+binding operation.
      Throws:
      tools.jackson.core.JacksonException
    • _readMapAndClose

      protected Object _readMapAndClose(DeserializationContextExt ctxt, tools.jackson.core.JsonParser p0, JavaType valueType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _readTreeAndClose

      protected JsonNode _readTreeAndClose(DeserializationContextExt ctxt, tools.jackson.core.JsonParser p0) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _deserializationContext

      protected DeserializationContextExt _deserializationContext(tools.jackson.core.JsonParser p)
      Internal helper method called to create an instance of DeserializationContext for deserializing a single root value. Can be overridden if a custom context is needed.
    • _deserializationContext

      public DeserializationContextExt _deserializationContext()
    • _deserializationContext

      protected DeserializationContextExt _deserializationContext(DeserializationConfig config, tools.jackson.core.JsonParser p)
    • _initForReading

      protected tools.jackson.core.JsonToken _initForReading(tools.jackson.core.JsonParser p, JavaType targetType) throws tools.jackson.core.JacksonException
      Method called to ensure that given parser is ready for reading content for data binding.
      Returns:
      First token to be used for data binding after this call: can never be null as exception will be thrown if parser cannot provide more tokens.
      Throws:
      tools.jackson.core.JacksonException - if the initialization fails during initialization of the streaming parser
    • _verifyNoTrailingTokens

      protected final void _verifyNoTrailingTokens(tools.jackson.core.JsonParser p, DeserializationContext ctxt, JavaType bindType) throws tools.jackson.core.JacksonException
      Throws:
      tools.jackson.core.JacksonException
    • _newReader

      protected ObjectReader _newReader(DeserializationConfig config)
      Factory method sub-classes must override, to produce ObjectReader instances of proper sub-type
    • _newReader

      protected ObjectReader _newReader(DeserializationConfig config, JavaType valueType, Object valueToUpdate, tools.jackson.core.FormatSchema schema, InjectableValues injectableValues)
      Factory method sub-classes must override, to produce ObjectReader instances of proper sub-type
    • _newWriter

      protected ObjectWriter _newWriter(SerializationConfig config)
      Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type
    • _newWriter

      protected ObjectWriter _newWriter(SerializationConfig config, tools.jackson.core.FormatSchema schema)
      Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type
    • _newWriter

      protected ObjectWriter _newWriter(SerializationConfig config, JavaType rootType, tools.jackson.core.PrettyPrinter pp)
      Factory method sub-classes must override, to produce ObjectWriter instances of proper sub-type
    • _findRootDeserializer

      protected ValueDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt, JavaType valueType) throws tools.jackson.core.JacksonException
      Method called to locate deserializer for the passed root-level value.
      Throws:
      tools.jackson.core.JacksonException
    • _verifySchemaType

      protected void _verifySchemaType(tools.jackson.core.FormatSchema schema)
    • _assertNotNull

      protected final void _assertNotNull(String paramName, Object src)