CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Core annotations used for value types, used by Jackson data binding package.

Pending
Overview
Eval results
Files

property-control.mddocs/

Property Control

Core annotations for controlling property serialization, naming, and access patterns in Jackson data binding.

Capabilities

JsonProperty

Primary annotation for controlling property serialization and deserialization behavior.

/**
 * Annotation for controlling property serialization and deserialization
 * @param value Property name in JSON (default: use field/method name)
 * @param namespace XML namespace for property (default: "")
 * @param required Whether property is required during deserialization (legacy)
 * @param isRequired Whether property is required (preferred over required)
 * @param index Ordering hint for property serialization (-1 = no ordering)
 * @param defaultValue Default value for property documentation
 * @param access Read/write access control for the property
 */
@JsonProperty(String value = "",
              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 {
        /** Default access (read-write) */
        AUTO,
        
        /** Property only used during serialization (read-only) */
        READ_ONLY,
        
        /** Property only used during deserialization (write-only) */
        WRITE_ONLY,
        
        /** Property used for both serialization and deserialization */
        READ_WRITE
    }
    
    /** Default property name marker */
    String USE_DEFAULT_NAME = "";
    
    /** Unknown index marker */
    int INDEX_UNKNOWN = -1;
}

Usage Examples:

public class User {
    // Basic property renaming
    @JsonProperty("firstName")
    private String name;
    
    // Required property
    @JsonProperty(value = "userId", required = true)
    private Long id;
    
    // Read-only property (only serialized)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private String createdAt;
    
    // Write-only property (only deserialized)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;
    
    // Property ordering
    @JsonProperty(value = "email", index = 1)
    private String emailAddress;
}

JsonAlias

Define alternative property names for deserialization flexibility.

/**
 * Define alternative property names accepted during deserialization
 * @param value Array of alternative property names
 */
@JsonAlias(String[] value)
public @interface JsonAlias;

Usage Examples:

public class Product {
    // Accept multiple property names during deserialization
    @JsonProperty("productName")
    @JsonAlias({"name", "title", "product_name"})
    private String name;
    
    // Handle different naming conventions
    @JsonProperty("price")
    @JsonAlias({"cost", "amount", "priceValue"})
    private BigDecimal price;
}

// This will deserialize all of these JSON variations:
// {"productName": "Laptop", "price": 999.99}
// {"name": "Laptop", "cost": 999.99}
// {"title": "Laptop", "amount": 999.99}

JsonGetter

Mark a method as a getter for a logical property.

/**
 * Mark method as getter for a logical property
 * @param value Property name (default: derive from method name)
 */
@JsonGetter(String value = "")
public @interface JsonGetter;

Usage Examples:

public class Rectangle {
    private double width;
    private double height;
    
    @JsonGetter("area")
    public double calculateArea() {
        return width * height;
    }
    
    @JsonGetter  // Will use "perimeter" as property name
    public double getPerimeter() {
        return 2 * (width + height);
    }
}

// Serializes to: {"width": 5.0, "height": 3.0, "area": 15.0, "perimeter": 16.0}

JsonSetter

Mark a method as a setter with null handling configuration.

/**
 * Mark method as setter for a property with null handling
 * @param value Property name (default: derive from method name)
 * @param nulls How to handle null values
 * @param contentNulls How to handle null content (for collections/maps)
 */
@JsonSetter(String value = "",
            Nulls nulls = Nulls.DEFAULT,
            Nulls contentNulls = Nulls.DEFAULT)
public @interface JsonSetter;

Usage Examples:

public class User {
    private String name;
    private List<String> tags;
    
    // Skip setting if null value received
    @JsonSetter(value = "userName", nulls = Nulls.SKIP)
    public void setName(String name) {
        this.name = name;
    }
    
    // Fail on null values
    @JsonSetter(nulls = Nulls.FAIL)
    public void setTags(List<String> tags) {
        this.tags = tags;
    }
    
    // Convert null content to empty list
    @JsonSetter(contentNulls = Nulls.AS_EMPTY)
    public void setCategories(List<String> categories) {
        this.categories = categories != null ? categories : new ArrayList<>();
    }
}

JsonSetter.Value

Configuration class for programmatic JsonSetter configuration.

/**
 * Value class for JsonSetter configuration
 */
public static class JsonSetter.Value implements JacksonAnnotationValue<JsonSetter> {
    public static final JsonSetter.Value EMPTY;
    
    public static JsonSetter.Value forValueNulls(Nulls nulls);
    public static JsonSetter.Value forContentNulls(Nulls nulls);
    public static JsonSetter.Value forValueNulls(Nulls valueNulls, Nulls contentNulls);
    
    public Nulls getValueNulls();
    public Nulls getContentNulls();
    public JsonSetter.Value withValueNulls(Nulls nulls);
    public JsonSetter.Value withContentNulls(Nulls nulls);
}

Property Access Patterns

Basic Property Mapping

public class Person {
    @JsonProperty("full_name")
    private String name;
    
    @JsonProperty("birth_date")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate birthDate;
    
    // Constructor
    @JsonCreator
    public Person(@JsonProperty("full_name") String name,
                  @JsonProperty("birth_date") LocalDate birthDate) {
        this.name = name;
        this.birthDate = birthDate;
    }
}

Advanced Access Control

public class Account {
    @JsonProperty(value = "id", access = JsonProperty.Access.READ_ONLY)
    private Long accountId;
    
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;
    
    private String email;
    
    @JsonGetter("email")
    public String getEmailAddress() {
        return email;
    }
    
    @JsonSetter("email")
    public void setEmailAddress(String email) {
        this.email = email.toLowerCase();
    }
}

Multiple Name Support

public class LegacyData {
    @JsonProperty("currentName")
    @JsonAlias({"oldName", "legacy_name", "previousName"})
    private String name;
    
    @JsonProperty("status")
    @JsonAlias({"state", "condition"})
    private String status;
}

JsonPropertyDescription

Provide human-readable descriptions for properties, used in JSON schema generation.

/**
 * Define human-readable description for a logical property
 * @param value Description text for the property
 */
@JsonPropertyDescription(String value = "")
public @interface JsonPropertyDescription;

Usage Examples:

public class Product {
    @JsonProperty("id")
    @JsonPropertyDescription("Unique identifier for the product")
    private Long productId;
    
    @JsonProperty("name")
    @JsonPropertyDescription("Human-readable product name")
    private String displayName;
    
    @JsonProperty("price")
    @JsonPropertyDescription("Product price in USD, formatted as decimal")
    private BigDecimal price;
    
    @JsonPropertyDescription("Date when product was first created")
    private LocalDateTime createdAt;
}

Install with Tessl CLI

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

docs

configuration.md

formatting.md

inclusion-exclusion.md

index.md

object-creation.md

object-identity.md

object-structure.md

polymorphic-types.md

property-control.md

tile.json