com.fasterxml.jackson.core

Class ObjectCodec

  • All Implemented Interfaces:
    Versioned


    public abstract class ObjectCodec
    extends TreeCodec
    implements Versioned
    Abstract class that defines the interface that JsonParser and JsonGenerator use to serialize and deserialize regular Java objects (POJOs aka Beans).

    The standard implementation of this class is com.fasterxml.jackson.databind.ObjectMapper, defined in the "jackson-databind".

    • Constructor Detail

      • ObjectCodec

        protected ObjectCodec()
    • Method Detail

      • version

        public abstract Version version()
        Description copied from interface: Versioned
        Method called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (see Version for details).
        Specified by:
        version in interface Versioned
      • readValue

        public abstract <T> T readValue(JsonParser p,
                                        Class<T> valueType)
                                 throws IOException
        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 can not be introspected when using this method.

        Throws:
        IOException
      • readValue

        public abstract <T> T readValue(JsonParser p,
                                        TypeReference<T> valueTypeRef)
                                 throws IOException
        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" and specifically needs to be used if the root type is a parameterized (generic) container type.
        Throws:
        IOException
      • readValue

        public abstract <T> T readValue(JsonParser p,
                                        ResolvedType valueType)
                                 throws IOException
        Method to deserialize JSON content into a POJO, type specified with fully resolved type object (so it can be a generic type, including containers like Collection and Map).
        Throws:
        IOException
      • readValues

        public abstract <T> Iterator<T> readValues(JsonParser p,
                                                   Class<T> valueType)
                                            throws IOException
        Method for reading sequence of Objects from parser stream, all with same specified value type.
        Throws:
        IOException
      • readTree

        public abstract <T extends TreeNode> T readTree(JsonParser p)
                                                 throws IOException
        Method to deserialize JSON content as tree expressed using set of TreeNode 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). Empty or whitespace documents return null.
        Specified by:
        readTree in class TreeCodec
        Returns:
        next tree from p, or null if empty.
        Throws:
        IOException
      • createObjectNode

        public abstract TreeNode createObjectNode()
        Method for construct root level Object nodes for Tree Model instances.
        Specified by:
        createObjectNode in class TreeCodec
      • createArrayNode

        public abstract TreeNode createArrayNode()
        Method for construct root level Array nodes for Tree Model instances.
        Specified by:
        createArrayNode in class TreeCodec
      • treeToValue

        public abstract <T> T treeToValue(TreeNode n,
                                          Class<T> valueType)
                                   throws JsonProcessingException
        Convenience method for converting given JSON tree into instance of specified value type. This is equivalent to first constructing a JsonParser to iterate over contents of the tree, and using that parser for data binding.
        Throws:
        JsonProcessingException
      • getFactory

        public JsonFactory getFactory()
        Accessor for finding underlying data format factory (JsonFactory) codec will use for data binding.
        Since:
        2.1

Copyright © 2008–2019 FasterXML. All rights reserved.