Core annotations used for value types, used by Jackson data binding package.
npx @tessl/cli install tessl/maven-com-fasterxml-jackson-core--jackson-annotations@2.19.0Jackson Annotations is a zero-dependency library providing core annotations for Jackson data binding. It enables developers to control JSON serialization and deserialization behavior through annotations, supporting property renaming, type information handling, object creation patterns, and fine-grained control over the serialization process.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.19.0</version>
</dependency>import com.fasterxml.jackson.annotation.*;Specific imports:
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeInfo;import com.fasterxml.jackson.annotation.*;
public class Person {
@JsonProperty("firstName")
private String name;
@JsonIgnore
private String password;
@JsonProperty(required = true)
private int age;
@JsonCreator
public Person(@JsonProperty("firstName") String name,
@JsonProperty("age") int age) {
this.name = name;
this.age = age;
}
// getters and setters
}Jackson Annotations follows a declarative annotation-based approach with several key components:
@JsonProperty, @JsonIgnore, @JsonAlias)@JsonUnwrapped, @JsonValue, @JsonRawValue)@JsonTypeInfo, @JsonSubTypes, @JsonTypeName)@JsonCreator, @JacksonInject)@JacksonAnnotation, @JacksonAnnotationsInside)JacksonAnnotationValue implementationsAnnotations for controlling basic property serialization, naming, and access patterns. Essential for mapping Java field names to JSON properties and controlling visibility.
@JsonProperty(String value = JsonProperty.USE_DEFAULT_NAME,
String namespace = "",
boolean required = false,
OptBoolean isRequired = OptBoolean.DEFAULT,
int index = JsonProperty.INDEX_UNKNOWN,
String defaultValue = "",
JsonProperty.Access access = JsonProperty.Access.AUTO)
public @interface JsonProperty {
enum Access { AUTO, READ_ONLY, WRITE_ONLY, READ_WRITE }
String USE_DEFAULT_NAME = "";
int INDEX_UNKNOWN = -1;
}
@JsonAlias(String[] value = {})
public @interface JsonAlias;
@JsonGetter(String value = "")
public @interface JsonGetter;
@JsonSetter(String value = "", Nulls nulls = Nulls.DEFAULT,
Nulls contentNulls = Nulls.DEFAULT)
public @interface JsonSetter;
@JsonPropertyDescription(String value = "")
public @interface JsonPropertyDescription;Control which properties are included or excluded during serialization and deserialization, with support for conditional inclusion and unknown property handling.
@JsonIgnore(boolean value = true)
public @interface JsonIgnore;
@JsonIgnoreProperties(String[] value = {}, boolean ignoreUnknown = false,
boolean allowGetters = false, boolean allowSetters = false)
public @interface JsonIgnoreProperties;
@JsonInclude(JsonInclude.Include value = JsonInclude.Include.ALWAYS,
JsonInclude.Include content = JsonInclude.Include.ALWAYS,
Class<?> valueFilter = Void.class,
Class<?> contentFilter = Void.class)
public @interface JsonInclude {
enum Include { ALWAYS, NON_NULL, NON_ABSENT, NON_EMPTY, NON_DEFAULT, CUSTOM, USE_DEFAULTS }
}Annotations that modify how objects are structured in JSON, including unwrapping nested objects and controlling value representation.
@JsonUnwrapped(boolean enabled = true, String prefix = "", String suffix = "")
public @interface JsonUnwrapped;
@JsonValue(boolean value = true)
public @interface JsonValue;
@JsonRawValue(boolean value = true)
public @interface JsonRawValue;Control how objects are created during deserialization, including constructor/factory method selection and dependency injection.
@JsonCreator(JsonCreator.Mode mode = JsonCreator.Mode.DEFAULT)
public @interface JsonCreator {
enum Mode { DEFAULT, DELEGATING, PROPERTIES, DISABLED }
}
@JacksonInject(String value = "", OptBoolean useInput = OptBoolean.DEFAULT)
public @interface JacksonInject;Comprehensive support for handling polymorphic types with type information inclusion and subtype registration.
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE, include = JsonTypeInfo.As.PROPERTY,
property = "", Class<?> defaultImpl = JsonTypeInfo.class,
boolean visible = false,
OptBoolean requireTypeIdForSubtypes = OptBoolean.DEFAULT)
public @interface JsonTypeInfo {
enum Id { NONE, CLASS, MINIMAL_CLASS, NAME, SIMPLE_NAME, DEDUCTION, CUSTOM }
enum As { PROPERTY, WRAPPER_OBJECT, WRAPPER_ARRAY, EXTERNAL_PROPERTY, EXISTING_PROPERTY }
}
@JsonSubTypes(JsonSubTypes.Type[] value, boolean failOnRepeatedNames = false)
public @interface JsonSubTypes {
@interface Type {
Class<?> value();
String name() default "";
String[] names() default {};
}
}Handle circular references and object identity with configurable ID generation and reference management.
@JsonIdentityInfo(String property = "@id",
Class<? extends ObjectIdGenerator<?>> generator,
Class<? extends ObjectIdResolver> resolver = SimpleObjectIdResolver.class,
Class<?> scope = Object.class)
public @interface JsonIdentityInfo;
@JsonManagedReference(String value = "defaultReference")
public @interface JsonManagedReference;
@JsonBackReference(String value = "defaultReference")
public @interface JsonBackReference;Control serialization format for dates, numbers, and other values with comprehensive formatting options.
@JsonFormat(String pattern = "", JsonFormat.Shape shape = JsonFormat.Shape.ANY,
String locale = JsonFormat.DEFAULT_LOCALE,
String timezone = JsonFormat.DEFAULT_TIMEZONE,
OptBoolean lenient = OptBoolean.DEFAULT,
JsonFormat.Feature[] with = {},
JsonFormat.Feature[] without = {})
public @interface JsonFormat {
enum Shape { ANY, NATURAL, SCALAR, ARRAY, OBJECT, NUMBER, NUMBER_FLOAT,
NUMBER_INT, STRING, BOOLEAN, BINARY }
}
@JsonEnumDefaultValue
public @interface JsonEnumDefaultValue;Auto-detection configuration, filtering, and meta-annotation support for creating custom annotation combinations.
@JsonAutoDetect(JsonAutoDetect.Visibility getterVisibility = JsonAutoDetect.Visibility.DEFAULT,
JsonAutoDetect.Visibility isGetterVisibility = JsonAutoDetect.Visibility.DEFAULT,
JsonAutoDetect.Visibility setterVisibility = JsonAutoDetect.Visibility.DEFAULT,
JsonAutoDetect.Visibility creatorVisibility = JsonAutoDetect.Visibility.DEFAULT,
JsonAutoDetect.Visibility fieldVisibility = JsonAutoDetect.Visibility.DEFAULT)
public @interface JsonAutoDetect {
enum Visibility { ANY, NON_PRIVATE, PROTECTED_AND_PUBLIC, PUBLIC_ONLY, NONE, DEFAULT }
}
@JsonClassDescription(String value = "")
public @interface JsonClassDescription;Core enums and utility classes used throughout the annotation system:
public enum OptBoolean {
TRUE, FALSE, DEFAULT;
public boolean asBoolean();
public boolean asPrimitive();
public static OptBoolean fromBoolean(Boolean b);
}
public enum Nulls {
SET, SKIP, FAIL, AS_EMPTY, DEFAULT
}
public enum PropertyAccessor {
GETTER, SETTER, CREATOR, FIELD, IS_GETTER, NONE, ALL;
public boolean creatorEnabled();
public boolean getterEnabled();
public boolean isGetterEnabled();
public boolean setterEnabled();
public boolean fieldEnabled();
}
// JsonFormat constants
public static final String DEFAULT_LOCALE = "##default";
public static final String DEFAULT_TIMEZONE = "##default";