CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-fasterxml-jackson-core--jackson-databind

General data-binding functionality for Jackson: works on core streaming API

Pending
Overview
Eval results
Files

object-mapping.mddocs/

Object Mapping

The core functionality of Jackson Databind centers around ObjectMapper, ObjectReader, and ObjectWriter classes. These provide the main API for reading and writing JSON to/from Java objects (POJOs), with ObjectMapper serving as the primary entry point and factory for the other components.

ObjectMapper

ObjectMapper is the main API class that provides functionality for reading and writing JSON, either to/from basic POJOs or to/from a general-purpose JSON Tree Model (JsonNode). It also acts as a factory for more advanced ObjectReader and ObjectWriter classes.

public class ObjectMapper extends ObjectCodec implements Versioned, Serializable {
    // Construction
    public ObjectMapper();
    public ObjectMapper(JsonFactory jf);
    public ObjectMapper(JsonFactory jf, DefaultSerializerProvider sp, DefaultDeserializationContext dc);
    
    // Reading from String
    public <T> T readValue(String content, Class<T> valueType) throws JsonProcessingException;
    public <T> T readValue(String content, TypeReference<T> valueTypeRef) throws JsonProcessingException;
    public <T> T readValue(String content, JavaType valueType) throws JsonProcessingException;
    
    // Reading from InputStream
    public <T> T readValue(InputStream src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(InputStream src, TypeReference<T> valueTypeRef) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(InputStream src, JavaType valueType) throws IOException, StreamReadException, DatabindException;
    
    // Reading from Reader  
    public <T> T readValue(Reader src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(Reader src, TypeReference<T> valueTypeRef) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(Reader src, JavaType valueType) throws IOException, StreamReadException, DatabindException;
    
    // Reading from URL and File
    public <T> T readValue(URL src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(File src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(URL src, TypeReference<T> valueTypeRef) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(File src, TypeReference<T> valueTypeRef) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(URL src, JavaType valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(File src, JavaType valueType) throws IOException, StreamReadException, DatabindException;
    
    // Reading from byte arrays
    public <T> T readValue(byte[] src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(byte[] src, int offset, int len, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(byte[] src, TypeReference<T> valueTypeRef) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(byte[] src, int offset, int len, TypeReference<T> valueTypeRef) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(byte[] src, JavaType valueType) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(byte[] src, int offset, int len, JavaType valueType) throws IOException, StreamReadException, DatabindException;
    
    // Reading from DataInput
    public <T> T readValue(DataInput src, Class<T> valueType) throws IOException;
    public <T> T readValue(DataInput src, JavaType valueType) throws IOException;
    
    // Reading sequences/arrays 
    public <T> MappingIterator<T> readValues(JsonParser p, Class<T> valueType) throws IOException;
    public <T> MappingIterator<T> readValues(JsonParser p, TypeReference<T> valueTypeRef) throws IOException;
    public <T> MappingIterator<T> readValues(JsonParser p, JavaType valueType) throws IOException;
    
    // Writing to String
    public String writeValueAsString(Object value) throws JsonProcessingException;
    
    // Writing to byte arrays
    public byte[] writeValueAsBytes(Object value) throws JsonProcessingException;
    
    // Writing to OutputStream
    public void writeValue(OutputStream out, Object value) throws IOException, StreamWriteException, DatabindException;
    
    // Writing to Writer
    public void writeValue(Writer w, Object value) throws IOException, StreamWriteException, DatabindException;
    
    // Writing to File
    public void writeValue(File resultFile, Object value) throws IOException, StreamWriteException, DatabindException;
    
    // Writing to DataOutput
    public void writeValue(DataOutput out, Object value) throws IOException;
    
    // Writing to JsonGenerator
    public void writeValue(JsonGenerator g, Object value) throws IOException, StreamWriteException, DatabindException;
    
    // Tree model methods
    public JsonNode readTree(String content) throws JsonProcessingException;
    public JsonNode readTree(InputStream in) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(Reader r) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(JsonParser p) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(byte[] content) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(File file) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(URL source) throws IOException, StreamReadException, DatabindException;
    
    public void writeTree(JsonGenerator g, TreeNode rootNode) throws IOException, StreamWriteException, DatabindException;
    public void writeTree(JsonGenerator g, JsonNode rootNode) throws IOException, StreamWriteException, DatabindException;
    
    // Object conversion
    public <T> T convertValue(Object fromValue, Class<T> toValueType) throws IllegalArgumentException;
    public <T> T convertValue(Object fromValue, TypeReference<T> toValueTypeRef) throws IllegalArgumentException; 
    public <T> T convertValue(Object fromValue, JavaType toValueType) throws IllegalArgumentException;
    
    // Updating existing objects
    public ObjectReader readerForUpdating(Object valueToUpdate);
    public <T> T updateValue(T valueToUpdate, Object overrides) throws JsonMappingException;
    
    // Factory methods for ObjectReader  
    public ObjectReader reader();
    public ObjectReader reader(DeserializationFeature feature);
    public ObjectReader reader(DeserializationFeature first, DeserializationFeature... other);
    public ObjectReader readerFor(Class<?> type);
    public ObjectReader readerFor(JavaType type);
    public ObjectReader readerFor(TypeReference<?> type);
    public ObjectReader readerWithView(Class<?> view);
    
    // Factory methods for ObjectWriter
    public ObjectWriter writer();
    public ObjectWriter writer(SerializationFeature feature);
    public ObjectWriter writer(SerializationFeature first, SerializationFeature... other);
    public ObjectWriter writer(DateFormat df);
    public ObjectWriter writerWithView(Class<?> serializationView);
    public ObjectWriter writerFor(Class<?> rootType);
    public ObjectWriter writerFor(TypeReference<?> rootType);
    public ObjectWriter writerFor(JavaType rootType);
    public ObjectWriter writer(PrettyPrinter pp);
    public ObjectWriter writerWithDefaultPrettyPrinter();
    public ObjectWriter writer(FilterProvider filterProvider);
    
    // Configuration
    public ObjectMapper configure(SerializationFeature f, boolean state);
    public ObjectMapper configure(DeserializationFeature f, boolean state);
    public ObjectMapper configure(MapperFeature f, boolean state);
    public ObjectMapper configure(JsonParser.Feature f, boolean state);
    public ObjectMapper configure(JsonGenerator.Feature f, boolean state);
    public ObjectMapper configure(JsonFactory.Feature f, boolean state);
    
    public ObjectMapper enable(SerializationFeature... features);
    public ObjectMapper disable(SerializationFeature... features);
    public ObjectMapper enable(DeserializationFeature... features);
    public ObjectMapper disable(DeserializationFeature... features);
    public ObjectMapper enable(MapperFeature... features);
    public ObjectMapper disable(MapperFeature... features);
    
    // Configuration checking
    public boolean isEnabled(SerializationFeature f);
    public boolean isEnabled(DeserializationFeature f); 
    public boolean isEnabled(MapperFeature f);
    public boolean isEnabled(JsonParser.Feature f);
    public boolean isEnabled(JsonGenerator.Feature f);
    public boolean isEnabled(JsonFactory.Feature f);
    
    // Type factory access
    public TypeFactory getTypeFactory();
    public ObjectMapper setTypeFactory(TypeFactory tf);
    
    // Advanced configuration
    public ObjectMapper setSerializerFactory(SerializerFactory f);
    public SerializerFactory getSerializerFactory();
    public ObjectMapper setSerializerProvider(DefaultSerializerProvider p);
    public SerializerProvider getSerializerProvider();
    public ObjectMapper setMixInAnnotations(Map<Class<?>, Class<?>> sourceMixins);
    public ObjectMapper addMixIn(Class<?> target, Class<?> mixinSource);
    public Class<?> findMixInClassFor(Class<?> cls);
    public int mixInCount();
    
    // Modules
    public ObjectMapper registerModule(Module module);
    public ObjectMapper registerModules(Module... modules);
    public ObjectMapper registerModules(Iterable<? extends Module> modules);
    public Set<Object> getRegisteredModuleIds();
    
    // Subtypes  
    public void registerSubtypes(Class<?>... classes);
    public void registerSubtypes(NamedType... types);
    public void registerSubtypes(Collection<Class<?>> subtypes);
    
    // Copy and factory
    public ObjectMapper copy();
    public JsonFactory getFactory();
    
    // Node factory
    public JsonNodeFactory getNodeFactory();
    public ObjectMapper setNodeFactory(JsonNodeFactory f);
    
    // Context attributes
    public ObjectMapper setDefaultAttributes(ContextAttributes attrs);
    public ContextAttributes getDefaultAttributes();
    
    // Advanced settings
    public ObjectMapper setDefaultPrettyPrinter(PrettyPrinter pp);
    public void setSerializationInclusion(JsonInclude.Include incl);
    public ObjectMapper setPropertyNamingStrategy(PropertyNamingStrategy s);
    public PropertyNamingStrategy getPropertyNamingStrategy();
    public ObjectMapper setDefaultSetterInfo(JsonSetter.Value v);
    public ObjectMapper setDefaultVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility);
    public ObjectMapper setDefaultMergeable(Boolean b);
    public ObjectMapper setDefaultLeniency(Boolean b);
    
    // Polymorphic type validation
    public ObjectMapper activateDefaultTyping(PolymorphicTypeValidator ptv);
    public ObjectMapper activateDefaultTyping(PolymorphicTypeValidator ptv, ObjectMapper.DefaultTyping dti);
    public ObjectMapper activateDefaultTyping(PolymorphicTypeValidator ptv, ObjectMapper.DefaultTyping dti, JsonTypeInfo.As implType);
    public ObjectMapper deactivateDefaultTyping();
    public PolymorphicTypeValidator getPolymorphicTypeValidator();
    
    // Injectable values
    public ObjectMapper setInjectableValues(InjectableValues injectableValues);
    public InjectableValues getInjectableValues();
    
    // Locale and TimeZone
    public ObjectMapper setLocale(Locale l);
    public ObjectMapper setTimeZone(TimeZone tz);
    
    // Date handling
    public ObjectMapper setDateFormat(DateFormat dateFormat);
    public DateFormat getDateFormat();
    
    // Handler instantiation
    public ObjectMapper setHandlerInstantiator(HandlerInstantiator hi);
    public HandlerInstantiator getHandlerInstantiator();
    
    // Base64 variant
    public ObjectMapper setBase64Variant(Base64Variant v);
    public Base64Variant getBase64Variant();
    
    // Configuration access
    public SerializationConfig getSerializationConfig();
    public DeserializationConfig getDeserializationConfig();
}

public enum DefaultTyping {
    JAVA_LANG_OBJECT,
    OBJECT_AND_NON_CONCRETE,
    NON_CONCRETE_AND_ARRAYS, 
    NON_FINAL,
    EVERYTHING;
}

ObjectReader

ObjectReader is a builder-style factory for configuring JsonParser instances for reading JSON content. It provides a fluent API for creating configured instances that can be reused efficiently.

public class ObjectReader implements Versioned, Serializable {
    // Reading methods matching ObjectMapper
    public <T> T readValue(InputStream src) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(Reader src) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(String src) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(byte[] src) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(byte[] src, int offset, int length) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(File src) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(URL src) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(JsonNode src) throws IOException, StreamReadException, DatabindException;
    public <T> T readValue(DataInput src) throws IOException;
    
    // Reading with JsonParser
    public <T> T readValue(JsonParser p) throws IOException, StreamReadException, DatabindException;
    
    // Reading sequences
    public <T> MappingIterator<T> readValues(InputStream src) throws IOException, StreamReadException, DatabindException;
    public <T> MappingIterator<T> readValues(Reader src) throws IOException, StreamReadException, DatabindException;
    public <T> MappingIterator<T> readValues(String json) throws IOException, StreamReadException, DatabindException;
    public <T> MappingIterator<T> readValues(byte[] src, int offset, int length) throws IOException, StreamReadException, DatabindException;
    public <T> MappingIterator<T> readValues(byte[] src) throws IOException, StreamReadException, DatabindException;
    public <T> MappingIterator<T> readValues(File src) throws IOException, StreamReadException, DatabindException;
    public <T> MappingIterator<T> readValues(URL src) throws IOException, StreamReadException, DatabindException;
    public <T> MappingIterator<T> readValues(JsonParser p) throws IOException, StreamReadException, DatabindException;
    
    // Tree reading
    public JsonNode readTree(InputStream in) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(Reader r) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(String content) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(byte[] content) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(byte[] content, int offset, int len) throws IOException, StreamReadException, DatabindException;
    public JsonNode readTree(DataInput src) throws IOException;
    
    // Configuration - Features
    public ObjectReader with(DeserializationFeature feature);
    public ObjectReader with(DeserializationFeature first, DeserializationFeature... other);
    public ObjectReader withFeatures(DeserializationFeature... features);
    public ObjectReader without(DeserializationFeature feature);
    public ObjectReader without(DeserializationFeature first, DeserializationFeature... other);
    public ObjectReader withoutFeatures(DeserializationFeature... features);
    
    // Configuration - Type
    public ObjectReader forType(Class<?> valueType);
    public ObjectReader forType(JavaType valueType);
    public ObjectReader forType(TypeReference<?> valueTypeRef);
    
    // Configuration - Root name
    public ObjectReader withRootName(String rootName);
    public ObjectReader withRootName(PropertyName rootName);
    public ObjectReader withoutRootName();
    
    // Configuration - View
    public ObjectReader withView(Class<?> activeView);
    
    // Configuration - Type factory
    public ObjectReader with(TypeFactory tf);
    
    // Configuration - Injectable values
    public ObjectReader with(InjectableValues injectableValues);
    
    // Configuration - Attributes
    public ObjectReader withAttributes(Map<?, ?> attrs);
    public ObjectReader withAttribute(Object key, Object value);
    public ObjectReader withoutAttribute(Object key);
    
    // Configuration - Parser features  
    public ObjectReader with(JsonParser.Feature feature);
    public ObjectReader withFeatures(JsonParser.Feature... features);
    public ObjectReader without(JsonParser.Feature feature);
    public ObjectReader withoutFeatures(JsonParser.Feature... features);
    
    // Configuration - Format features
    public ObjectReader with(FormatFeature feature);
    public ObjectReader withFeatures(FormatFeature... features);  
    public ObjectReader without(FormatFeature feature);
    public ObjectReader withoutFeatures(FormatFeature... features);
    
    // Configuration - Schema
    public ObjectReader with(FormatSchema schema);
    
    // Configuration - Base64
    public ObjectReader with(Base64Variant defaultBase64);
    
    // Configuration - Character escaping
    public ObjectReader with(CharacterEscapes escapes);
    
    // Configuration - Context attributes
    public ObjectReader with(ContextAttributes attrs);
    
    // Configuration access
    public boolean isEnabled(DeserializationFeature f);
    public boolean isEnabled(MapperFeature f);
    public boolean isEnabled(JsonParser.Feature f);
    public DeserializationConfig getConfig();
    public JsonFactory getFactory();
    public TypeFactory getTypeFactory();
    public ContextAttributes getAttributes();
    
    // Value type access
    public JavaType getValueType();
    
    // Versioning  
    public Version version();
}

ObjectWriter

ObjectWriter is a builder-style factory for configuring JsonGenerator instances for writing JSON content. It provides a fluent API for creating configured instances for efficient reuse.

public class ObjectWriter implements Versioned, Serializable {
    // Writing methods matching ObjectMapper
    public void writeValue(OutputStream out, Object value) throws IOException, StreamWriteException, DatabindException;
    public void writeValue(Writer w, Object value) throws IOException, StreamWriteException, DatabindException;
    public void writeValue(File resultFile, Object value) throws IOException, StreamWriteException, DatabindException;
    public void writeValue(DataOutput out, Object value) throws IOException;
    
    // Writing to strings/bytes
    public String writeValueAsString(Object value) throws JsonProcessingException;
    public byte[] writeValueAsBytes(Object value) throws JsonProcessingException;
    
    // Writing with JsonGenerator
    public void writeValue(JsonGenerator g, Object value) throws IOException, StreamWriteException, DatabindException;
    
    // Sequence writing
    public SequenceWriter writeValues(OutputStream out) throws IOException;
    public SequenceWriter writeValues(Writer out) throws IOException;
    public SequenceWriter writeValues(File out) throws IOException;
    public SequenceWriter writeValues(DataOutput out) throws IOException;
    public SequenceWriter writeValuesAsArray(OutputStream out) throws IOException;
    public SequenceWriter writeValuesAsArray(Writer out) throws IOException;
    public SequenceWriter writeValuesAsArray(File out) throws IOException;
    public SequenceWriter writeValuesAsArray(DataOutput out) throws IOException;
    
    // Configuration - Features
    public ObjectWriter with(SerializationFeature feature);
    public ObjectWriter with(SerializationFeature first, SerializationFeature... other);
    public ObjectWriter withFeatures(SerializationFeature... features);
    public ObjectWriter without(SerializationFeature feature);
    public ObjectWriter without(SerializationFeature first, SerializationFeature... other);
    public ObjectWriter withoutFeatures(SerializationFeature... features);
    
    // Configuration - Type
    public ObjectWriter forType(Class<?> rootType);
    public ObjectWriter forType(JavaType rootType);
    public ObjectWriter forType(TypeReference<?> rootType);
    
    // Configuration - Root name
    public ObjectWriter withRootName(String rootName);
    public ObjectWriter withRootName(PropertyName rootName);
    public ObjectWriter withoutRootName();
    
    // Configuration - View
    public ObjectWriter withView(Class<?> view);
    
    // Configuration - Pretty printing
    public ObjectWriter with(PrettyPrinter pp);
    public ObjectWriter withDefaultPrettyPrinter();
    public ObjectWriter with(MinimalPrettyPrinter pp);
    
    // Configuration - Filter provider
    public ObjectWriter with(FilterProvider filterProvider);
    
    // Configuration - Date format
    public ObjectWriter with(DateFormat df);
    
    // Configuration - Type factory
    public ObjectWriter with(TypeFactory tf);
    
    // Configuration - Attributes
    public ObjectWriter withAttributes(Map<?, ?> attrs);
    public ObjectWriter withAttribute(Object key, Object value);
    public ObjectWriter withoutAttribute(Object key);
    
    // Configuration - Generator features
    public ObjectWriter with(JsonGenerator.Feature feature);
    public ObjectWriter withFeatures(JsonGenerator.Feature... features);
    public ObjectWriter without(JsonGenerator.Feature feature);
    public ObjectWriter withoutFeatures(JsonGenerator.Feature... features);
    
    // Configuration - Format features
    public ObjectWriter with(FormatFeature feature);
    public ObjectWriter withFeatures(FormatFeature... features);
    public ObjectWriter without(FormatFeature feature);
    public ObjectWriter withoutFeatures(FormatFeature... features);
    
    // Configuration - Schema
    public ObjectWriter with(FormatSchema schema);
    
    // Configuration - Base64
    public ObjectWriter with(Base64Variant b64variant);
    
    // Configuration - Character escaping
    public ObjectWriter with(CharacterEscapes escapes);
    
    // Configuration - Root value separator
    public ObjectWriter withRootValueSeparator(String sep);
    public ObjectWriter withRootValueSeparator(SerializableString sep);
    
    // Configuration access
    public boolean isEnabled(SerializationFeature f);
    public boolean isEnabled(MapperFeature f);
    public boolean isEnabled(JsonGenerator.Feature f);
    public SerializationConfig getConfig();
    public JsonFactory getFactory();
    public TypeFactory getTypeFactory();
    public boolean hasPrefixElements();
    
    // Versioning
    public Version version();
}

Usage Examples

Basic Object Mapping

import com.fasterxml.jackson.databind.ObjectMapper;

// Create mapper
ObjectMapper mapper = new ObjectMapper();

// Simple POJO
public class Person {
    public String name;
    public int age;
    public Person() {} // Default constructor required
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

// Writing object to JSON
Person person = new Person("John", 30);
String json = mapper.writeValueAsString(person);
// Result: {"name":"John","age":30}

// Reading JSON to object
String json = "{\"name\":\"Jane\", \"age\":25}";
Person person = mapper.readValue(json, Person.class);

// Reading from different sources
Person person1 = mapper.readValue(new File("person.json"), Person.class);
Person person2 = mapper.readValue(new URL("http://example.com/person.json"), Person.class);
Person person3 = mapper.readValue(inputStream, Person.class);

Generic Types with TypeReference

import com.fasterxml.jackson.core.type.TypeReference;
import java.util.List;
import java.util.Map;

ObjectMapper mapper = new ObjectMapper();

// Reading collections  
String jsonArray = "[{\"name\":\"John\",\"age\":30}, {\"name\":\"Jane\",\"age\":25}]";
List<Person> people = mapper.readValue(jsonArray, new TypeReference<List<Person>>() {});

// Reading maps
String jsonMap = "{\"person1\":{\"name\":\"John\",\"age\":30}, \"person2\":{\"name\":\"Jane\",\"age\":25}}";
Map<String, Person> personMap = mapper.readValue(jsonMap, new TypeReference<Map<String, Person>>() {});

// Complex nested generics
String complexJson = "{\"data\":[{\"items\":[{\"name\":\"item1\"}]}]}";
Map<String, List<Map<String, Object>>> complex = mapper.readValue(complexJson, 
    new TypeReference<Map<String, List<Map<String, Object>>>>() {});

ObjectReader Configuration

ObjectMapper mapper = new ObjectMapper();

// Create configured reader
ObjectReader reader = mapper.readerFor(Person.class)
    .with(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
    .without(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
    .withView(PublicView.class);

// Reuse configured reader
Person person1 = reader.readValue(json1);
Person person2 = reader.readValue(json2);
Person person3 = reader.readValue(inputStream);

// Reading sequences
MappingIterator<Person> iterator = reader.readValues(jsonArrayStream);
while (iterator.hasNextValue()) {
    Person person = iterator.nextValue();
    // Process person
}

ObjectWriter Configuration

ObjectMapper mapper = new ObjectMapper();

// Create configured writer
ObjectWriter writer = mapper.writerFor(Person.class)
    .with(SerializationFeature.INDENT_OUTPUT)
    .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
    .withView(PublicView.class)
    .withDefaultPrettyPrinter();

// Reuse configured writer
String json1 = writer.writeValueAsString(person1);
String json2 = writer.writeValueAsString(person2);
writer.writeValue(outputStream, person3);

// Writing sequences
SequenceWriter seqWriter = writer.writeValues(outputStream);
seqWriter.write(person1);
seqWriter.write(person2);
seqWriter.close();

Object Conversion

ObjectMapper mapper = new ObjectMapper();

// Convert between different object types
Map<String, Object> map = new HashMap<>();
map.put("name", "John");
map.put("age", 30);

Person person = mapper.convertValue(map, Person.class);

// Convert back
Map<String, Object> converted = mapper.convertValue(person, 
    new TypeReference<Map<String, Object>>() {});

// Update existing objects
Person existing = new Person("Jane", 25);
Person updates = new Person("Jane Smith", 26);
Person updated = mapper.updateValue(existing, updates);

Handling Errors

ObjectMapper mapper = new ObjectMapper();

try {
    Person person = mapper.readValue(invalidJson, Person.class);
} catch (JsonProcessingException e) {
    // Handle JSON parsing errors
    System.err.println("JSON processing error: " + e.getMessage());
} catch (IOException e) {
    // Handle IO errors
    System.err.println("IO error: " + e.getMessage());
}

// Configure error handling behavior
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);

Types

// Mapping iterator for sequences
public class MappingIterator<T> implements Iterator<T>, Closeable {
    public boolean hasNext();
    public boolean hasNextValue() throws IOException;
    public T next();
    public T nextValue() throws IOException;
    public void remove();
    public void close() throws IOException;
    public List<T> readAll() throws IOException;
    public List<T> readAll(List<T> resultList) throws IOException;
    public JsonLocation getCurrentLocation();
    public JsonParser getParser();
}

// Sequence writer for output sequences  
public class SequenceWriter implements Versioned, Closeable, Flushable {
    public SequenceWriter write(Object value) throws IOException;
    public SequenceWriter writeAll(Object[] array) throws IOException;
    public SequenceWriter writeAll(Iterable<?> iterable) throws IOException;
    public void close() throws IOException;
    public void flush() throws IOException;
    public Version version();
}

// Exception for databind operations
public abstract class DatabindException extends JsonProcessingException {
    public abstract void prependPath(Object referrer, String fieldName);
    public abstract void prependPath(Object referrer, int index);
    public abstract void prependPath(JsonMappingException.Reference r);
}

// Stream exceptions
public class StreamReadException extends JsonProcessingException {
    public StreamReadException(JsonParser p, String msg);
    public StreamReadException(JsonParser p, String msg, Throwable root);
    public JsonParser getProcessor();
    public RequestPayload getRequestPayload();
    public String getRequestPayloadAsString();
}

public class StreamWriteException extends JsonProcessingException {
    public StreamWriteException(JsonGenerator g, String msg);
    public StreamWriteException(JsonGenerator g, String msg, Throwable root);
    public JsonGenerator getProcessor();
}

Install with Tessl CLI

npx tessl i tessl/maven-com-fasterxml-jackson-core--jackson-databind

docs

advanced-features.md

annotations.md

configuration.md

deserialization.md

index.md

json-tree-model.md

modules.md

object-mapping.md

serialization.md

type-system.md

tile.json