Class ObjectReader
- java.lang.Object
-
- com.fasterxml.jackson.core.TreeCodec
-
- com.fasterxml.jackson.core.ObjectCodec
-
- com.fasterxml.jackson.databind.ObjectReader
-
- All Implemented Interfaces:
Versioned,java.io.Serializable
public class ObjectReader extends ObjectCodec implements Versioned, java.io.Serializable
Builder object that can be used for per-serialization configuration of deserialization parameters, such as root type to use or object to update (instead of constructing new instance).Uses "mutant factory" pattern so that instances are immutable (and thus fully thread-safe with no external synchronization); new instances are constructed for different configurations. Instances are initially constructed by
ObjectMapperand can be reused, shared, cached; both because of thread-safety and because instances are relatively light-weight.NOTE: this class is NOT meant as sub-classable (with Jackson 2.8 and above) by users. It is left as non-final mostly to allow frameworks that require bytecode generation for proxying and similar use cases, but there is no expecation that functionality should be extended by sub-classing.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ObjectReaderat(JsonPointer pointer)Convenience method to bind fromJsonPointerJsonPointerBasedFilteris registered and will be used for parsing later.ObjectReaderat(java.lang.String pointerExpr)Convenience method to bind fromJsonPointer.JsonNodecreateArrayNode()Method for construct root level Array nodes for Tree Model instances.JsonNodecreateObjectNode()Method for construct root level Object nodes for Tree Model instances.ObjectReaderforType(TypeReference<?> valueTypeRef)Method for constructing a new reader instance that is configured to data bind into specified type.ObjectReaderforType(JavaType valueType)Method for constructing a new reader instance that is configured to data bind into specified type.ObjectReaderforType(java.lang.Class<?> valueType)Method for constructing a new reader instance that is configured to data bind into specified type.ContextAttributesgetAttributes()DeserializationConfiggetConfig()JsonFactorygetFactory()Accessor for finding underlying data format factory (JsonFactory) codec will use for data binding.InjectableValuesgetInjectableValues()TypeFactorygetTypeFactory()JavaTypegetValueType()booleanisEnabled(JsonParser.Feature f)booleanisEnabled(DeserializationFeature f)booleanisEnabled(MapperFeature f)JsonNodemissingNode()JsonNodenullNode()JsonNodereadTree(byte[] json)Same asreadTree(InputStream)except content read from passed-in byte array.JsonNodereadTree(byte[] json, int offset, int len)Same asreadTree(InputStream)except content read from passed-in byte array.<T extends TreeNode>
TreadTree(JsonParser p)Convenience method that binds content read using given parser, using configuration of this reader, except that content is bound as JSON tree instead of configured root value type.JsonNodereadTree(java.io.DataInput src)Same asreadTree(InputStream)except content read using passed-inDataInput.JsonNodereadTree(java.io.InputStream src)Method that reads content from given input source, using configuration of this reader, and binds it as JSON Tree.JsonNodereadTree(java.io.Reader src)Same asreadTree(InputStream)except content accessed through passed-inReaderJsonNodereadTree(java.lang.String json)Same asreadTree(InputStream)except content read from passed-inString<T> TreadValue(byte[] src)Method that binds content read from given byte array, using configuration of this reader.<T> TreadValue(byte[] src, int offset, int length)Method that binds content read from given byte array, using configuration of this reader.<T> TreadValue(JsonParser p)Method that binds content read using given parser, using configuration of this reader, including expected result type.<T> TreadValue(JsonParser p, ResolvedType valueType)Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type).<T> TreadValue(JsonParser p, TypeReference<T> valueTypeRef)Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type).<T> TreadValue(JsonParser p, JavaType valueType)Type-safe overloaded method, basically alias forreadValue(JsonParser, ResolvedType).<T> TreadValue(JsonParser p, java.lang.Class<T> valueType)Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type).<T> TreadValue(JsonNode src)Convenience method for converting results from given JSON tree into given value type.<T> TreadValue(java.io.DataInput src)<T> TreadValue(java.io.File src)<T> TreadValue(java.io.InputStream src)Method that binds content read from given input source, using configuration of this reader.<T> TreadValue(java.io.Reader src)Method that binds content read from given input source, using configuration of this reader.<T> TreadValue(java.lang.String src)Method that binds content read from given JSON string, using configuration of this reader.<T> TreadValue(java.net.URL src)Method that binds content read from given input source, using configuration of this reader.<T> MappingIterator<T>readValues(byte[] src)Overloaded version ofreadValue(InputStream).<T> MappingIterator<T>readValues(byte[] src, int offset, int length)Overloaded version ofreadValue(InputStream).<T> MappingIterator<T>readValues(JsonParser p)Method for reading sequence of Objects from parser stream.<T> java.util.Iterator<T>readValues(JsonParser p, ResolvedType valueType)Convenience method that is equivalent to:<T> java.util.Iterator<T>readValues(JsonParser p, TypeReference<T> valueTypeRef)Convenience method that is equivalent to:<T> java.util.Iterator<T>readValues(JsonParser p, JavaType valueType)Convenience method that is equivalent to:<T> java.util.Iterator<T>readValues(JsonParser p, java.lang.Class<T> valueType)Convenience method that is equivalent to:<T> MappingIterator<T>readValues(java.io.DataInput src)<T> MappingIterator<T>readValues(java.io.File src)Overloaded version ofreadValue(InputStream).<T> MappingIterator<T>readValues(java.io.InputStream src)Method for reading sequence of Objects from parser stream.<T> MappingIterator<T>readValues(java.io.Reader src)Overloaded version ofreadValue(InputStream).<T> MappingIterator<T>readValues(java.lang.String json)Overloaded version ofreadValue(InputStream).<T> MappingIterator<T>readValues(java.net.URL src)Overloaded version ofreadValue(InputStream).JsonParsertreeAsTokens(TreeNode n)Method for constructing aJsonParserfor reading contents of a JSON tree, as if it was external serialized JSON content.<T> TtreeToValue(TreeNode n, java.lang.Class<T> valueType)Convenience method for converting given JSON tree into instance of specified value type.Versionversion()Method that will return version information stored in and read from jar that contains this class.ObjectReaderwith(Base64Variant defaultBase64)ObjectReaderwith(FormatFeature feature)Method for constructing a new reader instance that is configured with specified feature enabled.ObjectReaderwith(FormatSchema schema)Method for constructing a new instance with configuration that passes specifiedFormatSchematoJsonParserthat is constructed for parsing content.ObjectReaderwith(JsonFactory f)Method for constructing a new reader instance with configuration that uses passedJsonFactoryfor constructing underlying Readers.ObjectReaderwith(JsonParser.Feature feature)Method for constructing a new reader instance that is configured with specified feature enabled.ObjectReaderwith(ContextAttributes attrs)ObjectReaderwith(DeserializationConfig config)Mutant factory method that will construct a new instance that has specified underlyingDeserializationConfig.ObjectReaderwith(DeserializationFeature feature)Method for constructing a new reader instance that is configured with specified feature enabled.ObjectReaderwith(DeserializationFeature first, DeserializationFeature... other)Method for constructing a new reader instance that is configured with specified features enabled.ObjectReaderwith(InjectableValues injectableValues)Method for constructing a new instance with configuration that uses passedInjectableValuesto provide injectable values.ObjectReaderwith(JsonNodeFactory f)Method for constructing a new reader instance with configuration that uses passedJsonNodeFactoryfor constructingJsonNodeinstances.ObjectReaderwith(java.util.Locale l)ObjectReaderwith(java.util.TimeZone tz)ObjectReaderwithAttribute(java.lang.Object key, java.lang.Object value)ObjectReaderwithAttributes(java.util.Map<?,?> attrs)ObjectReaderwithFeatures(FormatFeature... features)Method for constructing a new reader instance that is configured with specified features enabled.ObjectReaderwithFeatures(JsonParser.Feature... features)Method for constructing a new reader instance that is configured with specified features enabled.ObjectReaderwithFeatures(DeserializationFeature... features)Method for constructing a new reader instance that is configured with specified features enabled.ObjectReaderwithFormatDetection(DataFormatReaders readers)Fluent factory method for constructing a reader that will try to auto-detect underlying data format, using specifiedDataFormatReaders.ObjectReaderwithFormatDetection(ObjectReader... readers)Fluent factory method for constructing a reader that will try to auto-detect underlying data format, using specified list ofJsonFactoryinstances, and defaultDataFormatReaderssettings (for customizedDataFormatReaders, you can construct instance yourself).ObjectReaderwithHandler(DeserializationProblemHandler h)ObjectReaderwithout(FormatFeature feature)Method for constructing a new reader instance that is configured with specified feature disabled.ObjectReaderwithout(JsonParser.Feature feature)Method for constructing a new reader instance that is configured with specified feature disabled.ObjectReaderwithout(DeserializationFeature feature)Method for constructing a new reader instance that is configured with specified feature disabled.ObjectReaderwithout(DeserializationFeature first, DeserializationFeature... other)Method for constructing a new reader instance that is configured with specified features disabled.ObjectReaderwithoutAttribute(java.lang.Object key)ObjectReaderwithoutFeatures(FormatFeature... features)Method for constructing a new reader instance that is configured with specified features disabled.ObjectReaderwithoutFeatures(JsonParser.Feature... features)Method for constructing a new reader instance that is configured with specified features disabled.ObjectReaderwithoutFeatures(DeserializationFeature... features)Method for constructing a new reader instance that is configured with specified features disabled.ObjectReaderwithoutRootName()Convenience method that is same as calling:withRootName("")which will forcibly prevent use of root name wrapping when writing values with thisObjectReader.ObjectReaderwithRootName(PropertyName rootName)ObjectReaderwithRootName(java.lang.String rootName)Method for constructing a new instance with configuration that specifies what root name to expect for "root name unwrapping".ObjectReaderwithType(TypeReference<?> valueTypeRef)Deprecated.since 2.5 UseforType(TypeReference)insteadObjectReaderwithType(JavaType valueType)Deprecated.since 2.5 UseforType(JavaType)insteadObjectReaderwithType(java.lang.Class<?> valueType)Deprecated.since 2.5 UseforType(Class)insteadObjectReaderwithType(java.lang.reflect.Type valueType)Deprecated.since 2.5 UseforType(Class)insteadObjectReaderwithValueToUpdate(java.lang.Object value)Method for constructing a new instance with configuration that updates passed Object (as root value), instead of constructing a new value.ObjectReaderwithView(java.lang.Class<?> activeView)Method for constructing a new instance with configuration that uses specified View for filtering.voidwriteTree(JsonGenerator g, TreeNode rootNode)voidwriteValue(JsonGenerator gen, java.lang.Object value)Method to serialize given Java Object, using generator provided.-
Methods inherited from class com.fasterxml.jackson.core.ObjectCodec
getJsonFactory
-
-
-
-
Method Detail
-
version
public Version version()
Method that will return version information stored in and read from jar that contains this class.- Specified by:
versionin interfaceVersioned- Specified by:
versionin classObjectCodec
-
with
public ObjectReader with(DeserializationFeature feature)
Method for constructing a new reader instance that is configured with specified feature enabled.
-
with
public ObjectReader with(DeserializationFeature first, DeserializationFeature... other)
Method for constructing a new reader instance that is configured with specified features enabled.
-
withFeatures
public ObjectReader withFeatures(DeserializationFeature... features)
Method for constructing a new reader instance that is configured with specified features enabled.
-
without
public ObjectReader without(DeserializationFeature feature)
Method for constructing a new reader instance that is configured with specified feature disabled.
-
without
public ObjectReader without(DeserializationFeature first, DeserializationFeature... other)
Method for constructing a new reader instance that is configured with specified features disabled.
-
withoutFeatures
public ObjectReader withoutFeatures(DeserializationFeature... features)
Method for constructing a new reader instance that is configured with specified features disabled.
-
with
public ObjectReader with(JsonParser.Feature feature)
Method for constructing a new reader instance that is configured with specified feature enabled.
-
withFeatures
public ObjectReader withFeatures(JsonParser.Feature... features)
Method for constructing a new reader instance that is configured with specified features enabled.
-
without
public ObjectReader without(JsonParser.Feature feature)
Method for constructing a new reader instance that is configured with specified feature disabled.
-
withoutFeatures
public ObjectReader withoutFeatures(JsonParser.Feature... features)
Method for constructing a new reader instance that is configured with specified features disabled.
-
with
public ObjectReader with(FormatFeature feature)
Method for constructing a new reader instance that is configured with specified feature enabled.- Since:
- 2.7
-
withFeatures
public ObjectReader withFeatures(FormatFeature... features)
Method for constructing a new reader instance that is configured with specified features enabled.- Since:
- 2.7
-
without
public ObjectReader without(FormatFeature feature)
Method for constructing a new reader instance that is configured with specified feature disabled.- Since:
- 2.7
-
withoutFeatures
public ObjectReader withoutFeatures(FormatFeature... features)
Method for constructing a new reader instance that is configured with specified features disabled.- Since:
- 2.7
-
at
public ObjectReader at(java.lang.String pointerExpr)
Convenience method to bind fromJsonPointer.JsonPointerBasedFilteris registered and will be used for parsing later.- Since:
- 2.6
-
at
public ObjectReader at(JsonPointer pointer)
Convenience method to bind fromJsonPointerJsonPointerBasedFilteris registered and will be used for parsing later.- Since:
- 2.6
-
with
public ObjectReader with(DeserializationConfig config)
Mutant factory method that will construct a new instance that has specified underlyingDeserializationConfig.NOTE: use of this method is not recommended, as there are many other re-configuration methods available.
-
with
public ObjectReader with(InjectableValues injectableValues)
Method for constructing a new instance with configuration that uses passedInjectableValuesto provide injectable values.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
with
public ObjectReader with(JsonNodeFactory f)
Method for constructing a new reader instance with configuration that uses passedJsonNodeFactoryfor constructingJsonNodeinstances.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
with
public ObjectReader with(JsonFactory f)
Method for constructing a new reader instance with configuration that uses passedJsonFactoryfor constructing underlying Readers.NOTE: only factories that DO NOT REQUIRE SPECIAL MAPPERS (that is, ones that return
falseforJsonFactory.requiresCustomCodec()) can be used: trying to use one that requires custom codec will throw exception- Since:
- 2.1
-
withRootName
public ObjectReader withRootName(java.lang.String rootName)
Method for constructing a new instance with configuration that specifies what root name to expect for "root name unwrapping". SeeMapperConfigBase.withRootName(String)for details.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
withRootName
public ObjectReader withRootName(PropertyName rootName)
- Since:
- 2.6
-
withoutRootName
public ObjectReader withoutRootName()
Convenience method that is same as calling:withRootName("")which will forcibly prevent use of root name wrapping when writing values with thisObjectReader.- Since:
- 2.6
-
with
public ObjectReader with(FormatSchema schema)
Method for constructing a new instance with configuration that passes specifiedFormatSchematoJsonParserthat is constructed for parsing content.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
forType
public ObjectReader forType(JavaType valueType)
Method for constructing a new reader instance that is configured to data bind into specified type.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Since:
- 2.5
-
forType
public ObjectReader forType(java.lang.Class<?> valueType)
Method for constructing a new reader instance that is configured to data bind into specified type.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Since:
- 2.5
-
forType
public ObjectReader forType(TypeReference<?> valueTypeRef)
Method for constructing a new reader instance that is configured to data bind into specified type.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
- Since:
- 2.5
-
withType
@Deprecated public ObjectReader withType(JavaType valueType)
Deprecated.since 2.5 UseforType(JavaType)instead
-
withType
@Deprecated public ObjectReader withType(java.lang.Class<?> valueType)
Deprecated.since 2.5 UseforType(Class)instead
-
withType
@Deprecated public ObjectReader withType(java.lang.reflect.Type valueType)
Deprecated.since 2.5 UseforType(Class)instead
-
withType
@Deprecated public ObjectReader withType(TypeReference<?> valueTypeRef)
Deprecated.since 2.5 UseforType(TypeReference)instead
-
withValueToUpdate
public ObjectReader withValueToUpdate(java.lang.Object value)
Method for constructing a new instance with configuration that updates passed Object (as root value), instead of constructing a new value.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
withView
public ObjectReader withView(java.lang.Class<?> activeView)
Method for constructing a new instance with configuration that uses specified View for filtering.Note that the method does NOT change state of this reader, but rather construct and returns a newly configured instance.
-
with
public ObjectReader with(java.util.Locale l)
-
with
public ObjectReader with(java.util.TimeZone tz)
-
withHandler
public ObjectReader withHandler(DeserializationProblemHandler h)
-
with
public ObjectReader with(Base64Variant defaultBase64)
-
withFormatDetection
public ObjectReader withFormatDetection(ObjectReader... readers)
Fluent factory method for constructing a reader that will try to auto-detect underlying data format, using specified list ofJsonFactoryinstances, and defaultDataFormatReaderssettings (for customizedDataFormatReaders, you can construct instance yourself). to construct appropriateJsonParserfor actual parsing.Note: since format detection only works with byte sources, it is possible to get a failure from some 'readValue()' methods. Also, if input cannot be reliably (enough) detected as one of specified types, an exception will be thrown.
Note: not all
JsonFactorytypes can be passed: specifically, ones that require "custom codec" (like XML factory) will not work. Instead, use method that takesObjectReaderinstances instead of factories.- Parameters:
readers- Data formats accepted, in decreasing order of priority (that is, matches checked in listed order, first match wins)- Returns:
- Newly configured writer instance
- Since:
- 2.1
-
withFormatDetection
public ObjectReader withFormatDetection(DataFormatReaders readers)
Fluent factory method for constructing a reader that will try to auto-detect underlying data format, using specifiedDataFormatReaders.NOTE: since format detection only works with byte sources, it is possible to get a failure from some 'readValue()' methods. Also, if input cannot be reliably (enough) detected as one of specified types, an exception will be thrown.
- Parameters:
readers- DataFormatReaders to use for detecting underlying format.- Returns:
- Newly configured writer instance
- Since:
- 2.1
-
with
public ObjectReader with(ContextAttributes attrs)
- Since:
- 2.3
-
withAttributes
public ObjectReader withAttributes(java.util.Map<?,?> attrs)
- Since:
- 2.3
-
withAttribute
public ObjectReader withAttribute(java.lang.Object key, java.lang.Object value)
- Since:
- 2.3
-
withoutAttribute
public ObjectReader withoutAttribute(java.lang.Object key)
- Since:
- 2.3
-
isEnabled
public boolean isEnabled(DeserializationFeature f)
-
isEnabled
public boolean isEnabled(MapperFeature f)
-
isEnabled
public boolean isEnabled(JsonParser.Feature f)
-
getConfig
public DeserializationConfig getConfig()
- Since:
- 2.2
-
getFactory
public JsonFactory getFactory()
Description copied from class:ObjectCodecAccessor for finding underlying data format factory (JsonFactory) codec will use for data binding.- Overrides:
getFactoryin classObjectCodec- Since:
- 2.1
-
getTypeFactory
public TypeFactory getTypeFactory()
-
getAttributes
public ContextAttributes getAttributes()
- Since:
- 2.3
-
getInjectableValues
public InjectableValues getInjectableValues()
- Since:
- 2.6
-
getValueType
public JavaType getValueType()
- Since:
- 2.10
-
readValue
public <T> T readValue(JsonParser p) throws java.io.IOException
Method that binds content read using given parser, using configuration of this reader, including expected result type. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).NOTE: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Throws:
java.io.IOException
-
readValue
public <T> T readValue(JsonParser p, java.lang.Class<T> valueType) throws java.io.IOException
Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type). Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).NOTE: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Specified by:
readValuein classObjectCodec- Throws:
java.io.IOException
-
readValue
public <T> T readValue(JsonParser p, TypeReference<T> valueTypeRef) throws java.io.IOException
Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type). Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).NOTE: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Specified by:
readValuein classObjectCodec- Throws:
java.io.IOException
-
readValue
public <T> T readValue(JsonParser p, ResolvedType valueType) throws java.io.IOException
Convenience method that binds content read using given parser, using configuration of this reader, except that expected value type is specified with the call (instead of currently configured root type). Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).NOTE: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Specified by:
readValuein classObjectCodec- Throws:
java.io.IOException
-
readValue
public <T> T readValue(JsonParser p, JavaType valueType) throws java.io.IOException
Type-safe overloaded method, basically alias forreadValue(JsonParser, ResolvedType).NOTE: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Throws:
java.io.IOException
-
readValues
public <T> java.util.Iterator<T> readValues(JsonParser p, java.lang.Class<T> valueType) throws java.io.IOException
Convenience method that is equivalent to:withType(valueType).readValues(p);
Method reads a 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
JsonParserMUST 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 surroundingSTART_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: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Specified by:
readValuesin classObjectCodec- Throws:
java.io.IOException
-
readValues
public <T> java.util.Iterator<T> readValues(JsonParser p, TypeReference<T> valueTypeRef) throws java.io.IOException
Convenience method that is equivalent to:withType(valueTypeRef).readValues(p);
Method reads a 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
JsonParserMUST 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 surroundingSTART_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: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Specified by:
readValuesin classObjectCodec- Throws:
java.io.IOException
-
readValues
public <T> java.util.Iterator<T> readValues(JsonParser p, ResolvedType valueType) throws java.io.IOException
Convenience method that is equivalent to:withType(valueType).readValues(p);
Method reads a 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
JsonParserMUST 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 surroundingSTART_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: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Specified by:
readValuesin classObjectCodec- Throws:
java.io.IOException
-
readValues
public <T> java.util.Iterator<T> readValues(JsonParser p, JavaType valueType) throws java.io.IOException
Convenience method that is equivalent to:withType(valueType).readValues(p);
Method reads a 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
JsonParserMUST 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 surroundingSTART_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: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Throws:
java.io.IOException
-
createArrayNode
public JsonNode createArrayNode()
Description copied from class:ObjectCodecMethod for construct root level Array nodes for Tree Model instances.- Specified by:
createArrayNodein classObjectCodec
-
createObjectNode
public JsonNode createObjectNode()
Description copied from class:ObjectCodecMethod for construct root level Object nodes for Tree Model instances.- Specified by:
createObjectNodein classObjectCodec
-
missingNode
public JsonNode missingNode()
- Overrides:
missingNodein classTreeCodec
-
treeAsTokens
public JsonParser treeAsTokens(TreeNode n)
Description copied from class:ObjectCodecMethod for constructing aJsonParserfor reading contents of a JSON tree, as if it was external serialized JSON content.- Specified by:
treeAsTokensin classObjectCodec
-
readTree
public <T extends TreeNode> T readTree(JsonParser p) throws java.io.IOException
Convenience method that binds content read using given parser, using configuration of this reader, except that content is bound as JSON tree instead of configured root value type. ReturnsJsonNodethat represents the root of the resulting tree, if there was content to read, ornullif no more content is accessible via passedJsonParser.NOTE! Behavior with end-of-input (no more content) differs between this
readTreemethod, and all other methods that take input source: latter will return "missing node", NOTnullNote: if an object was specified with
withValueToUpdate(java.lang.Object), it will be ignored.NOTE: this method never tries to auto-detect format, since actual (data-format specific) parser is given.
- Specified by:
readTreein classObjectCodec- Returns:
- next tree from p, or null if empty.
- Throws:
java.io.IOException
-
writeTree
public void writeTree(JsonGenerator g, TreeNode rootNode)
- Specified by:
writeTreein classObjectCodec
-
readValue
public <T> T readValue(java.io.InputStream src) throws java.io.IOExceptionMethod that binds content read from given input source, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).- Throws:
java.io.IOException
-
readValue
public <T> T readValue(java.io.Reader src) throws java.io.IOExceptionMethod that binds content read from given input source, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).- Throws:
java.io.IOException
-
readValue
public <T> T readValue(java.lang.String src) throws JsonProcessingException, JsonMappingExceptionMethod that binds content read from given JSON string, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).
-
readValue
public <T> T readValue(byte[] src) throws java.io.IOExceptionMethod that binds content read from given byte array, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).- Throws:
java.io.IOException
-
readValue
public <T> T readValue(byte[] src, int offset, int length) throws java.io.IOExceptionMethod that binds content read from given byte array, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).- Throws:
java.io.IOException
-
readValue
public <T> T readValue(java.io.File src) throws java.io.IOException- Throws:
java.io.IOException
-
readValue
public <T> T readValue(java.net.URL src) throws java.io.IOExceptionMethod that binds content read from given input source, using configuration of this reader. Value return is either newly constructed, or root value that was specified withwithValueToUpdate(Object).NOTE: handling of
URLis delegated toJsonFactory.createParser(java.net.URL)and usually simply callsURL.openStream(), meaning no special handling is done. If different HTTP connection options are needed you will need to createInputStreamseparately.- Throws:
java.io.IOException
-
readValue
public <T> T readValue(JsonNode src) throws java.io.IOException
Convenience method for converting results from given JSON tree into given value type. Basically short-cut for:objectReader.readValue(src.traverse())
- Throws:
java.io.IOException
-
readValue
public <T> T readValue(java.io.DataInput src) throws java.io.IOException- Throws:
java.io.IOException- Since:
- 2.8
-
readTree
public JsonNode readTree(java.io.InputStream src) throws java.io.IOException
Method that reads content from given input source, using configuration of this reader, and binds it as JSON Tree. ReturnsJsonNodethat represents the root of the resulting tree, if there was content to read, or "missing node" (instance of for whichJsonNode.isMissingNode()returns true, and behaves otherwise similar to "null node") if no more content is accessible through passed-in input source.NOTE! Behavior with end-of-input (no more content) differs between this
readTreemethod, andreadTree(JsonParser)-- latter returnsnullfor "no content" case.Note that if an object was specified with a call to
withValueToUpdate(Object)it will just be ignored; result is always a newly constructedJsonNodeinstance.- Throws:
java.io.IOException
-
readTree
public JsonNode readTree(java.io.Reader src) throws java.io.IOException
Same asreadTree(InputStream)except content accessed through passed-inReader- Throws:
java.io.IOException
-
readTree
public JsonNode readTree(java.lang.String json) throws JsonProcessingException, JsonMappingException
Same asreadTree(InputStream)except content read from passed-inString
-
readTree
public JsonNode readTree(byte[] json) throws java.io.IOException
Same asreadTree(InputStream)except content read from passed-in byte array.- Throws:
java.io.IOException
-
readTree
public JsonNode readTree(byte[] json, int offset, int len) throws java.io.IOException
Same asreadTree(InputStream)except content read from passed-in byte array.- Throws:
java.io.IOException
-
readTree
public JsonNode readTree(java.io.DataInput src) throws java.io.IOException
Same asreadTree(InputStream)except content read using passed-inDataInput.- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(JsonParser p) throws java.io.IOException
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
JsonParsermust 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 surroundingSTART_ARRAYbut rather to the token following it.- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(java.io.InputStream src) throws java.io.IOException
Method for reading sequence of Objects from parser stream.Sequence can be either wrapped or unwrapped root-level sequence: wrapped means that the elements are enclosed in JSON Array; and unwrapped that elements are directly accessed at main level. Assumption is that iff the first token of the document is
START_ARRAY, we have a wrapped sequence; otherwise unwrapped. For wrapped sequences, leadingSTART_ARRAYis skipped, so that for both cases, underlyingJsonParserwill point to what is expected to be the first token of the first element.Note that the wrapped vs unwrapped logic means that it is NOT possible to use this method for reading an unwrapped sequence of elements written as JSON Arrays: to read such sequences, one has to use
readValues(JsonParser), making sure parser points to the first token of the first element (i.e. the secondSTART_ARRAYwhich is part of the first element).- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(java.io.Reader src) throws java.io.IOException
Overloaded version ofreadValue(InputStream).- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(java.lang.String json) throws java.io.IOException
Overloaded version ofreadValue(InputStream).- Parameters:
json- String that contains JSON content to parse- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(byte[] src, int offset, int length) throws java.io.IOException
Overloaded version ofreadValue(InputStream).- Throws:
java.io.IOException
-
readValues
public final <T> MappingIterator<T> readValues(byte[] src) throws java.io.IOException
Overloaded version ofreadValue(InputStream).- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(java.io.File src) throws java.io.IOException
Overloaded version ofreadValue(InputStream).- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(java.net.URL src) throws java.io.IOException
Overloaded version ofreadValue(InputStream).NOTE: handling of
URLis delegated toJsonFactory.createParser(java.net.URL)and usually simply callsURL.openStream(), meaning no special handling is done. If different HTTP connection options are needed you will need to createInputStreamseparately.- Parameters:
src- URL to read to access JSON content to parse.- Throws:
java.io.IOException
-
readValues
public <T> MappingIterator<T> readValues(java.io.DataInput src) throws java.io.IOException
- Throws:
java.io.IOException- Since:
- 2.8
-
treeToValue
public <T> T treeToValue(TreeNode n, java.lang.Class<T> valueType) throws JsonProcessingException
Description copied from class:ObjectCodecConvenience method for converting given JSON tree into instance of specified value type. This is equivalent to first constructing aJsonParserto iterate over contents of the tree, and using that parser for data binding.- Specified by:
treeToValuein classObjectCodec- Throws:
JsonProcessingException
-
writeValue
public void writeValue(JsonGenerator gen, java.lang.Object value) throws java.io.IOException
Description copied from class:ObjectCodecMethod to serialize given Java Object, using generator provided.- Specified by:
writeValuein classObjectCodec- Throws:
java.io.IOException
-
-