0
# Jackson Databind
1
2
Jackson Databind provides data-binding functionality for Jackson JSON processing - converts between Java objects and JSON. It works on top of Jackson's core streaming API and provides functionality for reading and writing JSON to/from POJOs (Plain Old Java Objects), a general-purpose JSON Tree Model, and advanced object concepts like polymorphism and object identity.
3
4
## Package Information
5
6
- **Package Name**: com.fasterxml.jackson.core/jackson-databind
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**:
10
```xml
11
<dependency>
12
<groupId>com.fasterxml.jackson.core</groupId>
13
<artifactId>jackson-databind</artifactId>
14
<version>2.20.0</version>
15
</dependency>
16
```
17
18
## Core Imports
19
20
```java
21
import com.fasterxml.jackson.databind.ObjectMapper;
22
import com.fasterxml.jackson.databind.JsonNode;
23
import com.fasterxml.jackson.databind.ObjectReader;
24
import com.fasterxml.jackson.databind.ObjectWriter;
25
import com.fasterxml.jackson.databind.JavaType;
26
```
27
28
## Basic Usage
29
30
```java
31
import com.fasterxml.jackson.databind.ObjectMapper;
32
import com.fasterxml.jackson.databind.JsonNode;
33
34
// Create ObjectMapper instance
35
ObjectMapper mapper = new ObjectMapper();
36
37
// Read JSON from string to POJO
38
String json = "{\"name\":\"John\", \"age\":30}";
39
Person person = mapper.readValue(json, Person.class);
40
41
// Write POJO to JSON string
42
String output = mapper.writeValueAsString(person);
43
44
// Read JSON as tree model
45
JsonNode tree = mapper.readTree(json);
46
String name = tree.get("name").asText();
47
```
48
49
## Architecture
50
51
Jackson Databind is built around several key components:
52
53
- **ObjectMapper**: Main entry point for all JSON processing operations
54
- **JsonNode**: Tree model for representing JSON in memory
55
- **ObjectReader/ObjectWriter**: Builder-style APIs for configured reading/writing
56
- **JavaType**: Type system for handling generic types and collections
57
- **Serialization Framework**: Pluggable serializers for converting objects to JSON
58
- **Deserialization Framework**: Pluggable deserializers for converting JSON to objects
59
- **Configuration System**: Features and settings for customizing behavior
60
- **Annotation System**: Annotations for controlling serialization/deserialization
61
62
## Capabilities
63
64
### Object Mapping
65
66
Core functionality for reading and writing JSON to/from Java objects, including POJOs, collections, and maps.
67
68
```java { .api }
69
public class ObjectMapper extends ObjectCodec implements Versioned, Serializable {
70
// Reading methods
71
public <T> T readValue(String content, Class<T> valueType) throws JsonProcessingException;
72
public <T> T readValue(String content, TypeReference<T> valueTypeRef) throws JsonProcessingException;
73
public <T> T readValue(String content, JavaType valueType) throws JsonProcessingException;
74
public <T> T readValue(InputStream src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
75
public <T> T readValue(Reader src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
76
public <T> T readValue(URL src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
77
public <T> T readValue(File src, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
78
79
// Writing methods
80
public String writeValueAsString(Object value) throws JsonProcessingException;
81
public byte[] writeValueAsBytes(Object value) throws JsonProcessingException;
82
public void writeValue(OutputStream out, Object value) throws IOException, StreamWriteException, DatabindException;
83
public void writeValue(Writer w, Object value) throws IOException, StreamWriteException, DatabindException;
84
public void writeValue(File resultFile, Object value) throws IOException, StreamWriteException, DatabindException;
85
86
// Tree model methods
87
public JsonNode readTree(String content) throws JsonProcessingException;
88
public JsonNode readTree(InputStream in) throws IOException, StreamReadException, DatabindException;
89
public JsonNode readTree(Reader r) throws IOException, StreamReadException, DatabindException;
90
public void writeTree(JsonGenerator g, JsonNode rootNode) throws IOException, StreamWriteException, DatabindException;
91
92
// Conversion methods
93
public <T> T convertValue(Object fromValue, Class<T> toValueType) throws IllegalArgumentException;
94
public <T> T convertValue(Object fromValue, TypeReference<T> toValueTypeRef) throws IllegalArgumentException;
95
public <T> T convertValue(Object fromValue, JavaType toValueType) throws IllegalArgumentException;
96
97
// Factory methods for readers/writers
98
public ObjectReader reader();
99
public ObjectReader readerFor(Class<?> type);
100
public ObjectReader readerFor(JavaType type);
101
public ObjectReader readerFor(TypeReference<?> type);
102
public ObjectWriter writer();
103
public ObjectWriter writerFor(Class<?> type);
104
public ObjectWriter writerFor(JavaType type);
105
106
// Additional reading methods
107
public <T> T readValue(JsonParser p, Class<T> valueType) throws IOException, StreamReadException, DatabindException;
108
public <T> T readValue(JsonParser p, TypeReference<T> valueTypeRef) throws IOException, StreamReadException, DatabindException;
109
public <T> T readValue(JsonParser p, JavaType valueType) throws IOException, StreamReadException, DatabindException;
110
111
// Additional writing methods
112
public void writeValue(JsonGenerator g, Object value) throws IOException, StreamWriteException, DatabindException;
113
114
// Configuration methods - Core Features
115
public ObjectMapper configure(SerializationFeature f, boolean state);
116
public ObjectMapper enable(SerializationFeature feature);
117
public ObjectMapper enable(SerializationFeature first, SerializationFeature... f);
118
public ObjectMapper disable(SerializationFeature feature);
119
public ObjectMapper disable(SerializationFeature first, SerializationFeature... f);
120
public ObjectMapper configure(DeserializationFeature f, boolean state);
121
public ObjectMapper enable(DeserializationFeature feature);
122
public ObjectMapper enable(DeserializationFeature first, DeserializationFeature... f);
123
public ObjectMapper disable(DeserializationFeature feature);
124
public ObjectMapper disable(DeserializationFeature first, DeserializationFeature... f);
125
126
// Module registration
127
public ObjectMapper registerModule(Module module);
128
public ObjectMapper registerModules(Module... modules);
129
public ObjectMapper registerModules(Iterable<? extends Module> modules);
130
public ObjectMapper findAndRegisterModules();
131
132
// Copy methods
133
public ObjectMapper copy();
134
135
// Key configuration setters
136
public ObjectMapper addMixIn(Class<?> target, Class<?> mixinSource);
137
public ObjectMapper setPropertyNamingStrategy(PropertyNamingStrategy s);
138
public ObjectMapper setSerializationInclusion(JsonInclude.Include incl);
139
public ObjectMapper setVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility);
140
}
141
```
142
143
[Object Mapping](./object-mapping.md)
144
145
### JSON Tree Model
146
147
Tree model API for working with JSON as in-memory tree structures, providing DOM-like navigation and manipulation.
148
149
```java { .api }
150
public abstract class JsonNode implements TreeNode, Iterable<JsonNode> {
151
// Navigation methods
152
public abstract JsonNode get(int index);
153
public JsonNode get(String fieldName);
154
public abstract JsonNode path(String fieldName);
155
public abstract JsonNode path(int index);
156
public JsonNode at(String jsonPtrExpr);
157
public JsonNode at(JsonPointer ptr);
158
159
// Type checking methods
160
public abstract boolean isArray();
161
public abstract boolean isObject();
162
public final boolean isValueNode();
163
public final boolean isContainerNode();
164
public final boolean isMissingNode();
165
public boolean isNull();
166
public boolean isTextual();
167
public boolean isNumber();
168
public boolean isBoolean();
169
170
// Value extraction methods
171
public String asText();
172
public String asText(String defaultValue);
173
public int asInt();
174
public int asInt(int defaultValue);
175
public long asLong();
176
public long asLong(long defaultValue);
177
public double asDouble();
178
public double asDouble(double defaultValue);
179
public boolean asBoolean();
180
public boolean asBoolean(boolean defaultValue);
181
182
// Raw value getters
183
public String textValue();
184
public byte[] binaryValue() throws IOException;
185
public boolean booleanValue();
186
public Number numberValue();
187
public short shortValue();
188
public int intValue();
189
public long longValue();
190
public float floatValue();
191
public double doubleValue();
192
public BigDecimal decimalValue();
193
public BigInteger bigIntegerValue();
194
195
// Additional type checking methods
196
public boolean isShort();
197
public boolean isInt();
198
public boolean isLong();
199
public boolean isFloat();
200
public boolean isDouble();
201
public boolean isBigDecimal();
202
public boolean isBigInteger();
203
public boolean isIntegralNumber();
204
public boolean isFloatingPointNumber();
205
public final boolean isPojo();
206
207
// Field/value existence checking
208
public boolean has(String fieldName);
209
public boolean has(int index);
210
public boolean hasNonNull(String fieldName);
211
public boolean hasNonNull(int index);
212
213
// Tree search methods
214
public abstract JsonNode findValue(String fieldName);
215
public final List<JsonNode> findValues(String fieldName);
216
public final List<String> findValuesAsText(String fieldName);
217
public abstract JsonNode findParent(String fieldName);
218
public final List<JsonNode> findParents(String fieldName);
219
220
// Tree modification methods
221
public abstract <T extends JsonNode> T deepCopy();
222
public JsonNode withObject(JsonPointer ptr);
223
public JsonNode withObject(String expr);
224
public JsonNode withObjectProperty(String propertyName);
225
public JsonNode withArray(JsonPointer ptr);
226
public JsonNode withArray(String expr);
227
public JsonNode withArrayProperty(String propertyName);
228
229
// Container methods
230
public abstract int size();
231
public abstract boolean isEmpty();
232
public Iterator<String> fieldNames();
233
public Iterator<Map.Entry<String, JsonNode>> fields();
234
public Iterator<JsonNode> elements();
235
}
236
```
237
238
[JSON Tree Model](./json-tree-model.md)
239
240
### Type System
241
242
Type representation system for handling generic types, collections, and complex type hierarchies safely.
243
244
```java { .api }
245
public abstract class JavaType extends ResolvedType implements Serializable {
246
// Type inspection
247
public abstract Class<?> getRawClass();
248
public abstract boolean hasRawClass(Class<?> clz);
249
public final boolean hasRawClass(Class<?> clz);
250
public final boolean isTypeOrSubTypeOf(Class<?> clz);
251
public final boolean isTypeOrSuperTypeOf(Class<?> clz);
252
public abstract boolean isArrayType();
253
public abstract boolean isCollectionLikeType();
254
public abstract boolean isMapLikeType();
255
public abstract boolean hasContentType();
256
public boolean isAbstract();
257
public boolean isConcrete();
258
public boolean isThrowable();
259
public final boolean isEnumType();
260
public final boolean isRecordType();
261
public boolean isPrimitive();
262
public final boolean isFinal();
263
264
// Generic type handling
265
public abstract JavaType getContentType();
266
public abstract JavaType getKeyType();
267
public abstract int containedTypeCount();
268
public abstract JavaType containedType(int index);
269
public abstract String containedTypeName(int index);
270
public abstract TypeBindings getBindings();
271
public abstract JavaType getSuperClass();
272
public abstract List<JavaType> getInterfaces();
273
public abstract JavaType[] findSuperTypes(Class<?> erasedTarget);
274
public abstract JavaType findTypeParameters(Class<?> expType);
275
276
// Type manipulation
277
public abstract JavaType withContentType(JavaType contentType);
278
public JavaType withTypeHandler(Object h);
279
public JavaType withContentTypeHandler(Object h);
280
public JavaType withValueHandler(Object h);
281
public JavaType withContentValueHandler(Object h);
282
public JavaType withHandlersFrom(JavaType src);
283
public abstract JavaType refine(Class<?> rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces);
284
public JavaType forcedNarrowBy(Class<?> subclass);
285
286
// Factory access
287
public static JavaType constructType(Type type);
288
}
289
```
290
291
[Type System](./type-system.md)
292
293
### Serialization
294
295
Framework for converting Java objects to JSON with customizable serializers and configuration.
296
297
```java { .api }
298
public abstract class JsonSerializer<T> {
299
// Core serialization
300
public abstract void serialize(T value, JsonGenerator gen, SerializerProvider serializers) throws IOException;
301
public void serializeWithType(T value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException;
302
303
// Metadata methods
304
public Class<T> handledType();
305
public boolean isEmpty(SerializerProvider provider, T value);
306
public boolean usesObjectId();
307
308
// Contextual serialization
309
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException;
310
311
// Schema support
312
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType type) throws JsonMappingException;
313
}
314
```
315
316
[Serialization](./serialization.md)
317
318
### Deserialization
319
320
Framework for converting JSON to Java objects with customizable deserializers and configuration.
321
322
```java { .api }
323
public abstract class JsonDeserializer<T> {
324
// Core deserialization
325
public abstract T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException;
326
public T deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException;
327
328
// Null and empty value handling
329
public T getNullValue(DeserializationContext ctxt) throws JsonMappingException;
330
public T getEmptyValue(DeserializationContext ctxt) throws JsonMappingException;
331
public AccessPattern getNullAccessPattern();
332
public AccessPattern getEmptyAccessPattern();
333
334
// Metadata methods
335
public Class<?> handledType();
336
public boolean isCachable();
337
public ObjectIdReader getObjectIdReader();
338
339
// Contextual deserialization
340
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException;
341
}
342
```
343
344
[Deserialization](./deserialization.md)
345
346
### Configuration
347
348
Configuration system for customizing Jackson behavior through features, settings, and overrides.
349
350
```java { .api }
351
public enum SerializationFeature implements ConfigFeature {
352
WRAP_ROOT_VALUE,
353
INDENT_OUTPUT,
354
FAIL_ON_EMPTY_BEANS,
355
FAIL_ON_SELF_REFERENCES,
356
WRAP_EXCEPTIONS,
357
FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS,
358
WRITE_SELF_REFERENCES_AS_NULL,
359
CLOSE_CLOSEABLE,
360
FLUSH_AFTER_WRITE_VALUE,
361
WRITE_DATES_AS_TIMESTAMPS,
362
WRITE_DATE_KEYS_AS_TIMESTAMPS,
363
WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS,
364
WRITE_ENUMS_USING_TO_STRING,
365
WRITE_ENUMS_USING_INDEX,
366
WRITE_ENUM_KEYS_USING_INDEX,
367
WRITE_NULL_MAP_VALUES,
368
WRITE_EMPTY_JSON_ARRAYS,
369
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED,
370
WRITE_BIGDECIMAL_AS_PLAIN,
371
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS,
372
ORDER_MAP_ENTRIES_BY_KEYS,
373
USE_EQUALITY_FOR_OBJECT_ID,
374
WRITE_DATES_WITH_ZONE_ID,
375
WRITE_DATES_WITH_CONTEXT_TIME_ZONE,
376
WRITE_DURATIONS_AS_TIMESTAMPS,
377
FAIL_ON_ORDER_MAP_BY_INCOMPARABLE_KEY,
378
EAGER_SERIALIZER_FETCH;
379
380
public boolean enabledByDefault();
381
public int getMask();
382
public boolean enabledIn(int flags);
383
}
384
385
public enum DeserializationFeature implements ConfigFeature {
386
USE_BIG_DECIMAL_FOR_FLOATS,
387
USE_BIG_INTEGER_FOR_INTS,
388
USE_LONG_FOR_INTS,
389
USE_JAVA_ARRAY_FOR_JSON_ARRAY,
390
FAIL_ON_UNKNOWN_PROPERTIES,
391
FAIL_ON_NULL_FOR_PRIMITIVES,
392
FAIL_ON_NUMBERS_FOR_ENUMS,
393
FAIL_ON_INVALID_SUBTYPE,
394
FAIL_ON_READING_DUP_TREE_KEY,
395
FAIL_ON_IGNORED_PROPERTIES,
396
FAIL_ON_UNRESOLVED_OBJECT_IDS,
397
FAIL_ON_MISSING_CREATOR_PROPERTIES,
398
FAIL_ON_NULL_CREATOR_PROPERTIES,
399
FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY,
400
FAIL_ON_TRAILING_TOKENS,
401
WRAP_EXCEPTIONS,
402
ACCEPT_SINGLE_VALUE_AS_ARRAY,
403
UNWRAP_SINGLE_VALUE_ARRAYS,
404
UNWRAP_ROOT_VALUE,
405
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
406
ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT,
407
ACCEPT_FLOAT_AS_INT,
408
READ_ENUMS_USING_TO_STRING,
409
READ_UNKNOWN_ENUM_VALUES_AS_NULL,
410
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE,
411
READ_DATE_TIMESTAMPS_AS_NANOSECONDS,
412
ADJUST_DATES_TO_CONTEXT_TIME_ZONE,
413
EAGER_DESERIALIZER_FETCH,
414
FAIL_ON_SUBTYPE_CLASS_NOT_REGISTERED,
415
FAIL_ON_UNEXPECTED_VIEW_PROPERTIES,
416
FAIL_ON_UNKNOWN_INJECT_VALUE;
417
418
public boolean enabledByDefault();
419
public int getMask();
420
public boolean enabledIn(int flags);
421
}
422
```
423
424
[Configuration](./configuration.md)
425
426
### Annotations
427
428
Jackson databind annotations for controlling serialization and deserialization behavior.
429
430
```java { .api }
431
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
432
@Retention(RetentionPolicy.RUNTIME)
433
@JacksonAnnotation
434
public @interface JsonSerialize {
435
Class<? extends JsonSerializer> using() default JsonSerializer.None.class;
436
Class<? extends JsonSerializer> contentUsing() default JsonSerializer.None.class;
437
Class<? extends JsonSerializer> keyUsing() default JsonSerializer.None.class;
438
Class<? extends JsonSerializer> nullsUsing() default JsonSerializer.None.class;
439
Class<?> as() default Void.class;
440
Class<?> keyAs() default Void.class;
441
Class<?> contentAs() default Void.class;
442
JsonSerialize.Inclusion include() default JsonSerialize.Inclusion.DEFAULT_INCLUSION;
443
JsonSerialize.Typing typing() default JsonSerialize.Typing.DEFAULT_TYPING;
444
445
public enum Inclusion {
446
ALWAYS, NON_NULL, NON_ABSENT, NON_EMPTY, NON_DEFAULT, CUSTOM, USE_DEFAULTS;
447
}
448
449
public enum Typing {
450
DYNAMIC, STATIC, DEFAULT_TYPING;
451
}
452
}
453
454
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
455
@Retention(RetentionPolicy.RUNTIME)
456
@JacksonAnnotation
457
public @interface JsonDeserialize {
458
Class<? extends JsonDeserializer> using() default JsonDeserializer.None.class;
459
Class<? extends JsonDeserializer> contentUsing() default JsonDeserializer.None.class;
460
Class<? extends JsonDeserializer> keyUsing() default KeyDeserializer.None.class;
461
Class<?> builder() default Void.class;
462
Class<?> as() default Void.class;
463
Class<?> keyAs() default Void.class;
464
Class<?> contentAs() default Void.class;
465
Class<? extends Converter> converter() default Converter.None.class;
466
Class<? extends Converter> contentConverter() default Converter.None.class;
467
}
468
469
// Additional important annotations
470
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
471
@Retention(RetentionPolicy.RUNTIME)
472
@JacksonAnnotation
473
public @interface JsonPOJOBuilder {
474
String buildMethodName() default "build";
475
String withPrefix() default "with";
476
}
477
478
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
479
@Retention(RetentionPolicy.RUNTIME)
480
@JacksonAnnotation
481
public @interface JsonNaming {
482
Class<? extends PropertyNamingStrategy> value();
483
}
484
485
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
486
@Retention(RetentionPolicy.RUNTIME)
487
@JacksonAnnotation
488
public @interface JsonAppend {
489
JsonAppend.Attr[] attrs() default {};
490
JsonAppend.Prop[] props() default {};
491
boolean prepend() default false;
492
493
public @interface Attr {
494
String value();
495
boolean required() default false;
496
}
497
498
public @interface Prop {
499
Class<? extends VirtualBeanPropertyWriter> value();
500
String name() default "";
501
String namespace() default "";
502
Class<?> type() default Object.class;
503
int index() default -1;
504
boolean required() default false;
505
}
506
}
507
```
508
509
[Annotations](./annotations.md)
510
511
### Modules
512
513
Module system for extending ObjectMapper functionality with additional serializers, deserializers, and features.
514
515
```java { .api }
516
public abstract class Module implements Versioned {
517
// Module metadata
518
public abstract String getModuleName();
519
public abstract Version version();
520
521
// Module setup
522
public abstract void setupModule(SetupContext context);
523
524
// Setup context interface
525
public static interface SetupContext {
526
// Configuration access
527
MapperConfig<?> getConfig();
528
DeserializationConfig getDeserializationConfig();
529
SerializationConfig getSerializationConfig();
530
531
// Registration methods
532
void addDeserializers(Deserializers d);
533
void addKeyDeserializers(KeyDeserializers d);
534
void addSerializers(Serializers s);
535
void addKeySerializers(Serializers s);
536
void addBeanDeserializerModifier(BeanDeserializerModifier mod);
537
void addBeanSerializerModifier(BeanSerializerModifier mod);
538
void addAbstractTypeResolver(AbstractTypeResolver resolver);
539
void addTypeModifier(TypeModifier modifier);
540
void addValueInstantiators(ValueInstantiators instantiators);
541
void setClassIntrospector(ClassIntrospector ci);
542
void insertAnnotationIntrospector(AnnotationIntrospector ai);
543
void appendAnnotationIntrospector(AnnotationIntrospector ai);
544
void registerSubtypes(Class<?>... subtypes);
545
void registerSubtypes(NamedType... subtypes);
546
void registerSubtypes(Collection<Class<?>> subtypes);
547
void setMixInAnnotations(Class<?> target, Class<?> mixinSource);
548
void addDeserializationProblemHandler(DeserializationProblemHandler handler);
549
void setNamingStrategy(PropertyNamingStrategy naming);
550
}
551
}
552
```
553
554
[Modules](./modules.md)
555
556
### Advanced Features
557
558
Advanced features including polymorphism, custom type handling, and object identity management.
559
560
```java { .api }
561
// Polymorphic type handling
562
public abstract class TypeResolverBuilder<T extends TypeResolverBuilder<T>> {
563
public abstract T inclusion(JsonTypeInfo.As includeAs);
564
public abstract T typeProperty(String propName);
565
public abstract T typeIdVisibility(boolean isVisible);
566
public abstract T defaultImpl(Class<?> defaultImpl);
567
public abstract TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType, Collection<NamedType> subtypes);
568
public abstract TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes);
569
}
570
571
// Injectable values for dependency injection
572
public abstract class InjectableValues {
573
public abstract Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) throws JsonMappingException;
574
575
public static class Std extends InjectableValues implements Serializable {
576
public Std();
577
public Std(Map<String, Object> values);
578
public Std addValue(String key, Object value);
579
public Std addValue(Class<?> key, Object value);
580
}
581
}
582
583
// Object identity support
584
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
585
@Retention(RetentionPolicy.RUNTIME)
586
@JacksonAnnotation
587
public @interface JsonIdentityInfo {
588
Class<? extends ObjectIdGenerator> generator();
589
String property() default "@id";
590
boolean resolver() default false;
591
Class<? extends ObjectIdResolver> resolver() default ObjectIdResolver.class;
592
Class<?> scope() default Object.class;
593
}
594
```
595
596
[Advanced Features](./advanced-features.md)
597
598
## Types
599
600
```java { .api }
601
// Core exception types
602
public class JsonProcessingException extends IOException {
603
public JsonProcessingException(String msg);
604
public JsonProcessingException(String msg, Throwable rootCause);
605
public JsonProcessingException(String msg, JsonLocation loc);
606
public JsonProcessingException(String msg, JsonLocation loc, Throwable rootCause);
607
public String getOriginalMessage();
608
public Object getProcessor();
609
public JsonLocation getLocation();
610
}
611
612
public class JsonMappingException extends DatabindException {
613
public static class Reference implements Serializable {
614
public Reference();
615
public Reference(Object from);
616
public Reference(Object from, String fieldName);
617
public Reference(Object from, int index);
618
public void setFrom(Object o);
619
public void setFieldName(String fieldName);
620
public void setIndex(int index);
621
public Object getFrom();
622
public String getFieldName();
623
public int getIndex();
624
}
625
626
public List<Reference> getPath();
627
public String getPathReference();
628
public void prependPath(Object referrer, String fieldName);
629
public void prependPath(Object referrer, int index);
630
public void prependPath(Reference r);
631
632
public static JsonMappingException from(JsonParser p, String msg);
633
public static JsonMappingException from(JsonParser p, String msg, Throwable problem);
634
public static JsonMappingException from(JsonGenerator g, String msg);
635
public static JsonMappingException from(JsonGenerator g, String msg, Throwable problem);
636
public static JsonMappingException from(DeserializationContext ctxt, String msg);
637
public static JsonMappingException from(DeserializationContext ctxt, String msg, Throwable t);
638
public static JsonMappingException from(SerializerProvider ctxt, String msg);
639
public static JsonMappingException from(SerializerProvider ctxt, String msg, Throwable problem);
640
}
641
642
// Specific exception types
643
public class MismatchedInputException extends JsonMappingException {
644
public MismatchedInputException(JsonParser p, String msg);
645
public MismatchedInputException(JsonParser p, String msg, JsonLocation loc);
646
public MismatchedInputException(JsonParser p, String msg, Class<?> targetType);
647
public MismatchedInputException(JsonParser p, String msg, JavaType targetType);
648
public Class<?> getTargetType();
649
}
650
651
public class InvalidDefinitionException extends JsonMappingException {
652
public InvalidDefinitionException(JsonParser p, String msg, BeanDescription beanDesc);
653
public InvalidDefinitionException(JsonParser p, String msg, JavaType type);
654
public JavaType getType();
655
}
656
657
public class InvalidFormatException extends MismatchedInputException {
658
public InvalidFormatException(JsonParser p, String msg, Object value, Class<?> targetType);
659
public Object getValue();
660
}
661
662
public class UnrecognizedPropertyException extends PropertyBindingException {
663
public UnrecognizedPropertyException(JsonParser p, String msg, JsonLocation loc, Class<?> referringClass, String propName, Collection<Object> propertyIds);
664
public Collection<Object> getKnownPropertyIds();
665
}
666
667
public class IgnoredPropertyException extends PropertyBindingException {
668
public IgnoredPropertyException(JsonParser p, String msg, JsonLocation loc, Class<?> referringClass, String propName, Collection<Object> propertyIds);
669
}
670
671
public abstract class PropertyBindingException extends JsonMappingException {
672
public String getPropertyName();
673
public Class<?> getReferringClass();
674
}
675
676
public class InvalidNullException extends MismatchedInputException {
677
public InvalidNullException(DeserializationContext ctxt, String msg, JsonLocation loc);
678
}
679
680
public class ValueInstantiationException extends JsonMappingException {
681
public ValueInstantiationException(JsonParser p, String msg, JavaType type);
682
public ValueInstantiationException(JsonParser p, String msg, JavaType type, Throwable cause);
683
public JavaType getType();
684
}
685
686
// Property naming
687
public class PropertyName implements Serializable {
688
public static final PropertyName USE_DEFAULT;
689
public static final PropertyName NO_NAME;
690
691
public PropertyName(String simpleName);
692
public PropertyName(String simpleName, String namespace);
693
public static PropertyName construct(String simpleName);
694
public static PropertyName construct(String simpleName, String ns);
695
696
public String getSimpleName();
697
public String getNamespace();
698
public boolean hasSimpleName();
699
public boolean hasNamespace();
700
701
public PropertyName withSimpleName(String simpleName);
702
public PropertyName withNamespace(String ns);
703
public PropertyName internSimpleName();
704
}
705
706
// Configuration features interface
707
public interface ConfigFeature {
708
boolean enabledByDefault();
709
int getMask();
710
boolean enabledIn(int flags);
711
}
712
713
// Access pattern enumeration
714
public enum AccessPattern {
715
ALWAYS_NULL,
716
CONSTANT,
717
DYNAMIC,
718
READ_ONLY,
719
WRITE_ONLY;
720
}
721
```