An open-source entry in TopGit's GitHub warehouse: FasterXML/jackson-annotations, 1.1k stars, Java. Core annotations (annotations that only depend on jackson-core) for Jackson data processor
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This project contains general purpose annotations for
Jackson Data Processor, used on value and handler types.
The only annotations not included are ones that require dependency
to the Databind package.
Note that only annotations themselves (and related value classes) are included, but no functionality
that uses annotations.
Project contains versions 2.0 and above: source code for earlier (1.x) versions is available from Jackson-1 repository.
Full Listing of Jackson Annotations details all available annotations;
Project Wiki gives more details.
Project is licensed under Apache License 2.0.
Note on annotation handling
This module only defines Jackson annotations and their basic semantics.
Actual handling and interpretation of annotations (such as inclusion rules,
container content handling, or Optional value processing) is implemented
by jackson-databind.
Release notes
Release notes for this component/repo are available in Jackson Releases page (unified for all official Jackson components).
NOTE: Annotations module is released with "simple" version like 2.20 without "patch" number -- except for rare case of critical fixes.
This change occurred with Jackson 2.20: prior to it, patch number was included but was meaningless: every patch version of a minor release was identical (so, 2.18.0 and, say, 2.18.4 were identical).
NOTE: Jackson 3.x components rely on 2.x annotations; there are no separate 3.x jackson-annotations versions released (there were RC versions up to 3.0-rc5 but not after that).
Usage, general
Improvements over typical Java annotations
In addition to regular usage (see below), there are couple of noteworthy improvements Jackson does:
Jackson annotations support full inheritance: meaning that you can ''override annotation definitions'', and not just class annotations but also method/field annotations!
Jackson annotations will also be inherited from interfaces:
precedence between base class and implemented interfaces is such that base-class has lower precedence than interfaces;
if multiple interfaces are implemented, then the precedence depends on the order as returned by the JVM.
Maven, Java package
All annotations are in Java package com.fasterxml.jackson.annotation.
To use annotations, you need to use Maven dependency:
Finally, you may even want to just ignore any "extra" properties from JSON (ones for which there is no counterpart in POJO). This can be done by adding:
@JsonIgnoreProperties(ignoreUnknown=true)
public class PojoWithAny {
public int value;
}
Annotations for choosing more/less specific types
Sometimes the type Jackson uses when reading or writing a property is not quite what you want:
When reading (deserializing), declared type may be a general type, but you know which exact implementation type to use
When writing (serializing), Jackson will by default use the specific runtime type; but you may not want to include all information from that type but rather just contents of its supertype.
These cases can be handled by following annotations:
public class ValueContainer {
// although nominal type is 'Value', we want to read JSON as 'ValueImpl'
@JsonDeserialize(as=ValueImpl.class)
public Value value;
// although runtime type may be 'AdvancedType', we really want to serialize
// as 'BasicType'; two ways to do this:
@JsonSerialize(as=BasicType.class)
// or could also use: @JsonSerialize(typing=Typing.STATIC)
public BasicType another;
}
Usage, intermediate
Using constructors or factory methods
By default, Jackson tries to use the "default" constructor (one that takes no arguments), when creating value instances. But you can also choose to use another constructor, or a static factory method to create instance. To do this, you will need to use annotation @JsonCreator, and possibly @JsonProperty annotations to bind names to arguments:
public class CtorPOJO {
private final int _x, _y;
@JsonCreator
public CtorPOJO(@JsonProperty("x") int x, @JsonProperty("y") int y) {
_x = x;
_y = y;
}
}
@JsonCreator can be used similarly for static factory methods.
But there is also an alternative usage, which is so-called "delegating" creator:
public class DelegatingPOJO {
private final int _x, _y;
@JsonCreator
public DelegatingPOJO(Map<String,Object> delegate) {
_x = (Integer) delegate.get("x");
_y = (Integer) delegate.get("y");
}
}
the difference being that the creator method can only take one argument, and that argument must NOT have @JsonProperty annotation.
Handling polymorphic types
If you need to read and write values of Objects where there are multiple possible subtypes (i.e. ones that exhibit polymorphism), you may need to enable inclusion of type information. This is needed so that Jackson can read back correct Object type when deserializing (reading JSON into Objects).
This can be done by adding @JsonTypeInfo annotation on ''base class'':
@JsonTypeInfo(use=Id.MINIMAL_CLASS, include=As.PROPERTY, property="type") // Include Java class simple-name as JSON property "type"
@JsonSubTypes({@Type(Car.class), @Type(Aeroplane.class)}) // Required for deserialization only
public abstract class Vehicle {
}
public class Car extends Vehicle {
public String licensePlate;
}
public class Aeroplane extends Vehicle {
public int wingSpan;
}
public class PojoWithTypedObjects {
public List<Vehicle> items;
}
Alternatively, @JsonTypeInfo(use=DEDUCTION) can be used to avoid requiring the 'type' field. For deserialization, types are deduced based
on the fields available. Exceptions will be raised if subtypes do not have a distinct signature of fieldnames or JSON does
not resolve to single known signature.
Note that @JsonTypeInfo has lots of configuration possibilities: for more information check out
Intro to polymorphic type handling
Changing property auto-detection
The default Jackson property detection rules will find:
All public fields
All public getters (getXxx() methods)
All setters (setXxx(value) methods), regardless of visibility)
But if this does not work, you can change visibility levels by using annotation @JsonAutoDetect.
If you wanted, for example, to auto-detect ALL fields (similar to how packages like GSON work), you could do:
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
public class POJOWithFields {
private int value;
}
or, to disable auto-detection of fields altogether:
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.NONE)
public class POJOWithNoFields {
// will NOT be included, unless there is access 'getValue()'
public int value;
}
Support
Community support
Jackson components are supported by the Jackson community through mailing lists, Gitter forum, Github issues. See Participation, Contributing for full details.
Enterprise support
Available as part of the Tidelift Subscription.
The maintainers of jackson-annotations and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
Further reading
Project-specific documentation:
Full Listing of Jackson Annotations details all available annotations.
jackson-annotations wiki
Backwards compatibility:
You can make Jackson 2 use Jackson 1 annotations with jackson-legacy-introspector
Related:
Databinding module has more documentation, since it is the main user of annotations.
TopGit's last sync did not record any GitHub topics for FasterXML/jackson-annotations. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on FasterXML/jackson-annotations?
The most recent commit recorded on FasterXML/jackson-annotations was 17 days ago, based on the GitHub push timestamp. The repository has 344 forks — one of the better signals of community interest.
How many stars does FasterXML/jackson-annotations have?
FasterXML/jackson-annotations has 1.1k GitHub stars — refresh the page for the live number, or check github.com/FasterXML/jackson-annotations. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is FasterXML/jackson-annotations written in?
FasterXML/jackson-annotations is written primarily in Java. GitHub's language field is based on the largest share of bytes in the default branch.
Where do I read more about FasterXML/jackson-annotations?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/FasterXML/jackson-annotations is the definitive source.
Read full README in the tab above.
Want a second opinion on jackson-annotations?
Ask an AI that can read this page — one click and you get its take on jackson-annotations.