pax_global_header00006660000000000000000000000064132317744100014514gustar00rootroot0000000000000052 comment=8f3ee1aa9045fef460ef578f5a956b4f7aa08d44 jackson-annotations-jackson-annotations-2.9.4/000077500000000000000000000000001323177441000214745ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/.gitattributes000066400000000000000000000001371323177441000243700ustar00rootroot00000000000000# Do not merge `pom.xml` from older version, as it will typically conflict pom.xml merge=ours jackson-annotations-jackson-annotations-2.9.4/.github/000077500000000000000000000000001323177441000230345ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/.github/ISSUE_TEMPLATE.md000066400000000000000000000021431323177441000255410ustar00rootroot00000000000000We appreciate issues as very valuable contributions, but just to make sure here are things that are important to do before filing an issue: * Only report issues (and perhaps request new features, FEATURE):,Usage Questions should be asked on [Jackson-users](https://groups.google.com/forum/#!search/jackson-users) list -- you are more likely to get help that way (and we will promptly close questions-as-issues) * This repo -- `jackson-annotations` -- only defines annotation types, and actual implementation of behavior is within `jackson-databind`, so very often this is NOT THE PLACE TO FILE AN ISSUE. * Check to see if this issue has already been reported (quick glance at existing issues): no deep search necessary, just quick sanity check * Include version information for Jackson version you use * (optional but highly recommended) Verify that the problem occurs with the latest patch of same minor version; and even better, if possible, try using the latest stable patch version * For example: if you observe an issue with version `2.4.1`, first upgrade to `2.4.6` to ensure problem has not already been fixed. jackson-annotations-jackson-annotations-2.9.4/.gitignore000066400000000000000000000002451323177441000234650ustar00rootroot00000000000000# use glob syntax. syntax: glob *.class *~ *.bak *.off *.old .DS_Store # building target # Eclipse .classpath .project .settings # IDEA *.iml *.ipr *.iws /.idea/ jackson-annotations-jackson-annotations-2.9.4/.travis.yml000066400000000000000000000015411323177441000236060ustar00rootroot00000000000000language: java jdk: - openjdk7 - openjdk8 # Below this line is configuration for deploying to the Sonatype OSS repo # http://blog.xeiam.com/2013/05/configure-travis-ci-to-deploy-snapshots.html before_install: "git clone -b travis `git config --get remote.origin.url` target/travis" after_success: "mvn deploy --settings target/travis/settings.xml" # whitelist branches: # no changes in legacy branches (minus pom updates), no need to build only: - master env: global: - secure: "a2T/bJVacCzBKfGW7ycW2aVLxupCUenLpRX6Neh/WLFf5wbIjTtKZpB94sxbVGTKNT+HQmwFynWhz7Dh3251fSZ4lfGcHBnUr5lpq1vo10aMBTJaMpk5vrTLn0AxGESxqOjQQkDhasdLpoXlv1EtVn7HqHLepAr0AIUl41XggfA=" - secure: "Gdl5m/gEm4FrCxOVnvCM13dipEhjaL4IXbEL2dsNhxwZ+lqD+8OAwObbPrTLuUZ+KTWctfsNauGTin1bDhi8m/Gh6jm71U+hGuA7/8cqgprZDhdARxG7fSOdr9Syp24JL7h5u5X43+a7m2KiC/iUcErIiVKPBcAisOj286GcFhc=" jackson-annotations-jackson-annotations-2.9.4/README.md000066400000000000000000000202431323177441000227540ustar00rootroot00000000000000# Overview 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](../../../jackson-databind). Project contains versions 2.0 and above: source code for earlier (1.x) versions is available from [Jackson-1](../../../jackson-1) SVN repository. Note that with version 1.x these annotations were part of the 'core jar'. [Full Listing of Jackson Annotations](../../wiki/Jackson-Annotations) details all available annotations; [Project Wiki](../../wiki) gives more details. Project is licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0). [![Build Status](https://travis-ci.org/FasterXML/jackson-annotations.png?branch=master)](https://travis-ci.org/FasterXML/jackson-annotations) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.core/jackson-annotations/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.core/jackson-annotations) [![Javadoc](https://javadoc-emblem.rhcloud.com/doc/com.fasterxml.jackson.core/jackson-annotations/badge.svg)](http://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-annotations) ----- ## Usage, general ### Improvements over typical Java annotations In addition to regular usage (see below), there are couple of noteworthy improvements Jackson does: * [Mix-in annotations](../../wiki/Mixin-Annotations) allow associating annotations on third-party classes ''without modifying classes''. * Jackson annotations support full inheritance: meaning that you can ''override annotation definitions'', and not just class annotations but also method/field annotations! ### Maven, Java package All annotations are in Java package `com.fasterxml.jackson.annotation`. To use annotations, you need to use Maven dependency: ```xml com.fasterxml.jackson.core jackson-annotations ${jackson-annotations-version} ``` or download jars from Maven repository (or via quick links on [Wiki](../../wiki)) ## Usage, simple Let's start with simple use cases: renaming or ignoring properties, and modifying types that are used. Note: while examples only show field properties, same annotations would work with method (getter/setter) properties. ### Annotations for renaming properties One of most common tasks is to change JSON name used for a property: for example: ```java public class Name { @JsonProperty("firstName") public String _first_name; } ``` would result in JSON like: ```json { "firstName" : "Bob" } ``` instead of ```json { "_first_name" : "Bob" } ``` ### Annotations for Ignoring properties Sometimes POJOs contain properties that you do not want to write out, so you can do: ```java public class Value { public int value; @JsonIgnore public int internalValue; } ``` and get JSON like: ```json { "value" : 42 } ``` or, you may get properties in JSON that you just want to skip: if so, you can use: ```java @JsonIgnoreProperties({ "extra", "uselessValue" }) public class Value { public int value; } ``` which would be able to handle JSON like: ```json { "value" : 42, "extra" : "fluffy", "uselessValue" : -13 } ``` 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: ```java @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: ```java 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: ```java 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: ```java public class DelegatingPOJO { private final int _x, _y; @JsonCreator public DelegatingPOJO(Map 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'': ```java // Include Java class name ("com.myempl.ImplClass") as JSON property "class" @JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="class") public abstract class BaseClass { } public class Impl1 extends BaseClass { public int x; } public class Impl2 extends BaseClass { public String name; } public class PojoWithTypedObjects { public List items; } ``` and this could result in serialized JSON like: ```json { "items" : [ { "class":"Impl2", "name":"Bob" }, { "class":"Impl1", "x":13 } ]} ``` Note that this annotation has lots of configuration possibilities: for more information check out [Intro to polymorphic type handling](http://www.cowtowncoder.com/blog/archives/2010/03/entry_372.html) ### 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: ```java @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY) public class POJOWithFields { private int value; } ``` or, to disable auto-detection of fields altogether: ```java @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.NONE) public class POJOWithNoFields { // will NOT be included, unless there is access 'getValue()' public int value; } ``` ----- # Further reading Project-specific documentation: * [Full Listing of Jackson Annotations](../../wiki/Jackson-Annotations) details all available annotations. * [Other documentation](../../wiki) Usage: * You can make Jackson 2 use Jackson 1 annotations with [jackson-legacy-introspector](https://github.com/Laures/jackson-legacy-introspector) Related: * [Databinding](https://github.com/FasterXML/jackson-databind) module has more documentation, since it is the main user of annotations. In addition, here are other useful links: * [Jackson Project Home](http://wiki.fasterxml.com/JacksonHome) * [Annotation documentation at FasterXML Wiki](http://wiki.fasterxml.com/JacksonAnnotations) covers 1.x annotations as well as 2.0 jackson-annotations-jackson-annotations-2.9.4/pom.xml000066400000000000000000000050361323177441000230150ustar00rootroot00000000000000 4.0.0 com.fasterxml.jackson jackson-parent 2.9.1 com.fasterxml.jackson.core jackson-annotations Jackson-annotations 2.9.4 bundle Core annotations used for value types, used by Jackson data binding package. 2008 http://github.com/FasterXML/jackson scm:git:git@github.com:FasterXML/jackson-annotations.git scm:git:git@github.com:FasterXML/jackson-annotations.git http://github.com/FasterXML/jackson-annotations jackson-annotations-2.9.4 1.6 1.6 2.5.3 com.fasterxml.jackson.annotation.*;version=${project.version} junit junit test org.apache.felix maven-bundle-plugin com.fasterxml.jackson.annotation jackson-annotations-jackson-annotations-2.9.4/release-notes/000077500000000000000000000000001323177441000242425ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/release-notes/VERSION000066400000000000000000000147521323177441000253230ustar00rootroot00000000000000Project: jackson-annotations NOTE: Annotations module will never contain changes in patch versions, only .0 releases can have changes. We may still release patch versions, but they will be identical to .0 versions, and only released for convenience (developers can line up all Jackson components with same patch version number). Main components will typically depend on .0 versions: please do NOT file issues against this being a bug; it is intentional. ------------------------------------------------------------------------ === Releases === ------------------------------------------------------------------------ 2.9.1 (07-Sep-2017) #123: Add Automatic-Module-Name (`com.fasterxml.jackson.annotation`) for JDK9 interoperability 2.9.0 (30-Jul-2017) #103: Add `JsonInclude.Include.CUSTOM`, properties for specifying filter(s) to use #104: Add `JsonSetter.nulls`, `JsonSetter.contentNulls` for configurable null handling #105: Add `JsonFormat.lenient` to allow configuring lenience of date/time deserializers #108: Allow `@JsonValue` on fields #109: Add `enabled` for `@JsonAnyGetter`, `@JsonAnySetter`, to allow disabling via mix-ins #113: Add `@JsonMerge` to support (deep) merging of properties #116: Add `@JsonAlias` annotation to allow specifying alternate names for a property #120: Add new properties for `@JacksonInject` - Allow use of `@JsonView` on classes, to specify Default View to use on non-annotated properties. 2.8.0 (04-Jul-2016) #65: Add new choice for `JsonFormat.Shape`, `NATURAL` #79: Change `@JsonTypeInfo.defaultImpl` default value to deprecate `JsonTypeInfo.None.class` #83: Add `@JsonEnumDefaultValue` for indicating default enum choice if no real match found (suggested by Alejandro R) #87: Add `@JsonIgnoreProperties.Value` to support merging of settings #89: Add `JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES` #95: Add `JsonFormat.Feature#ADJUST_DATES_TO_CONTEXT_TIME_ZONE` (suggested by Alexey B) 2.7.0 (10-Jan-2016) #73: Add `@JsonClassDescription` (suggested by ufoscout@github) #77: Add a new `ObjectIdGenerator`, `StringIdGenerator`, to allow arbitrary `String` Object Id usage - Major rewrite of merging of `JsonFormat.Value` and `JsonInclude.Value`, to allow for better multi-level defaults (global, per-type, property) 2.6.0 (17-Jul-2015) #43: Add `@JsonFormat(with=Feature.xxx)` to support things like `DeserializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED` on per-property basis. #56: Improve `ObjectIdGenerators.key()` to handle `null` appropriately by returning `null` #58: Add new properties for `@JsonIgnoreProperties`, "allowGetters", "allowSetters" #60: Add new value type, `OptBoolean`, for "optional booleans", to support proper handling and usage of default values, not just explicit true/false. #61: Add new property, `@JsonProperty.access` (and matching enum) to support read-only/write-only properties #64: Add `@Documented` for `@JsonPropertyDescription` (suggested by Zoltan S) - Add `JsonInclude.Include.NON_ABSENT` value, for excluding "absent" Optional values. - Add tag interface `JacksonAnnotationValue` for helper types used for encapsulating information for "complex" annotations (multi-property ones) 2.5.0 (01-Jan-2015) #47: Add `@JsonCreator.mode` property to explicitly choose between delegating- and property-based creators, or to disable specific creator (Mode.DISABLED) #48: Allow `@JsonView` for (method) parameters too #49: Add `@JsonTypeInfo.skipWritingDefault` #50: Add `ObjectIdGenerator.maySerializeAsObject()`, `ObjectIdGenerator.ObjectIdGenerator.maySerializeAsObject()` to support JSOG - Added `@JsonInclude.content` to allow specifying inclusion criteria for `java.util.Map` entries separate from inclusion of `Map` values themselves - Finalize fix for [databind#490], by ensuring new mapping initialized for new context - Added `@JsonProperty.defaultValue()` (related to [databind#596]) 2.4.0 (29-May-2014) #31: Allow use of `@JsonPropertyOrder` for properties (not just classes) #32: Add `@JsonProperty.index` - Add `JsonFormat.Value#timeZoneAsString` (needed by Joda module) - Add `@JsonRootName.namespace` to allow specifying of namespace with standard Jackson annotations (not just XML-specific ones that dataformat-xml provides) 2.3.0 (13-Nov-2013) #13: Add `@JsonPropertyDescription` (suggested by Net-A-Porter@github) #20: Allow use of `@JsonFilter` for properties (via fields, methods, constructor parameters) (note: although #15 -- Add `JsonTypeInfo.As.EXISTING` property to support new variation for including Type Id was included, jackson-databind does not yet support it as of 2.3.0) 2.2.0 (22-Apr-2013) No changes since 2.1.1 2.1.1 (11-Nov-2012) Fixes: * Make ObjectIdGenerator java.io.Serializable (needed when serializing ObjectMappers/-Writers/-Readers) 2.1.0 (08-Oct-2012) New features: * [Issue#4]: Add '@JsonIdentityReference', to support use case where values of a specific reference property are always serialized as ids, never as full POJO Improvements: * Added '@JsonIdentityInfo.firstAsID' property, to allow forcing all references to an Object to be serialized as id, including first one. * Fix OSGi artifact name to be fully-qualified 2.0.2 (14-May-2012) Fixes: * OSGi bundle name was accidentally changed in 2.0.1; reverted back to one used in 2.0.0, earlier (reported Pascal G) 2.0.1 (22-Apr-2012) Fixes: * [JACKSON-827] Fix incompatibilities with JDK 1.5 (2.0.0 accidentally required 1.6) (reported Pascal G) 2.0.0 (25-Mar-2012) Improvements: * [JACKSON-437]: Allow injecting of type id as POJO property, by setting new '@JsonTypeInfo.visible' property to true. * [JACKSON-669]: Allow prefix/suffix for @JsonUnwrapped properties (requested by Aner P) * [JACKSON-787]: @JsonIgnoredProperties can be used on properties too New features: * [JACKSON-107]: Add support for Object Identity (to handled cycles, shared refs), with @JsonIdentityInfo * [JACKSON-714] Add general-purpose '@JsonFormat' annotation * [JACKSON-752]: Add @JsonInclude (replacement of @JsonSerialize.include) * [JACKSON-754]: Add @JacksonAnnotationsInside for creating "annotation bundles" (also: AnnotationIntrospector.isAnnotationBundle()) Other: * Lots of miscellaneous refactoring; moving most annotations from databind into this package; only leaving ones that depend on databind package types ------------------------------------------------------------------------ === History: === ------------------------------------------------------------------------ [entries for versions 1.x and earlier not retained; refer to earlier releases) jackson-annotations-jackson-annotations-2.9.4/src/000077500000000000000000000000001323177441000222635ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/000077500000000000000000000000001323177441000232075ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/000077500000000000000000000000001323177441000241305ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/000077500000000000000000000000001323177441000247065ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/000077500000000000000000000000001323177441000267135ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/000077500000000000000000000000001323177441000303435ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotation/000077500000000000000000000000001323177441000325155ustar00rootroot00000000000000JacksonAnnotation.java000066400000000000000000000012171323177441000367250ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Meta-annotation (annotations used on other annotations) * used for marking all annotations that are * part of Jackson package. Can be used for recognizing all * Jackson annotations generically, and in future also for * passing other generic annotation configuration. */ @Target({ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface JacksonAnnotation { // for now, a pure tag annotation, no parameters } JacksonAnnotationValue.java000066400000000000000000000014421323177441000377220ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.Annotation; /** * Marker interface used by value classes like {@link JsonFormat.Value} that are used * to contain information from one of Jackson annotations, and can be directly * instantiated from those annotations, as well as programmatically constructed * and possibly merged. The reason for such marker is to allow generic handling of * some of the annotations, as well as to allow easier injection of configuration * from sources other than annotations. * * @since 2.6 */ public interface JacksonAnnotationValue { /** * Introspection method that may be used to find actual annotation that may be used * as the source for value instance. */ public Class valueFor(); } JacksonAnnotationsInside.java000066400000000000000000000014071323177441000402450ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Meta-annotation (annotations used on other annotations) * used for indicating that instead of using target annotation * (annotation annotated with this annotation), * Jackson should use meta-annotations it has. * This can be useful in creating "combo-annotations" by having * a container annotation, which needs to be annotated with this * annotation as well as all annotations it 'contains'. * * @since 2.0 */ @Target({ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JacksonAnnotationsInside { } JacksonInject.java000066400000000000000000000146141323177441000360340ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import com.fasterxml.jackson.annotation.JacksonAnnotation; /** * Jackson-specific annotation used for indicating that value of * annotated property will be "injected", i.e. set based on value * configured by ObjectMapper (usually on per-call basis). * Usually property is not deserialized from JSON, although it possible * to have injected value as default and still allow optional override * from JSON. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JacksonInject { /** * Logical id of the value to inject; if not specified (or specified * as empty String), will use id based on declared type of property. */ public String value() default ""; /** * Whether matching input value is used for annotated property or not; * if disabled (`OptBoolean.FALSE`), input value (if any) will be ignored; * otherwise it will override injected value. *

* Default is `OptBoolean.DEFAULT`, which translates to `OptBoolean.TRUE`: this is * for backwards compatibility (2.8 and earlier always allow binding input value). * * @since 2.9 */ public OptBoolean useInput() default OptBoolean.DEFAULT; /* /********************************************************** /* Value class used to enclose information, allow for /* merging of layered configuration settings, and eventually /* decouple higher level handling from Annotation types /* (which can not be implemented etc) /********************************************************** */ /** * Helper class used to contain information from a single {@link JacksonInject} * annotation, as well as to provide possible overrides from non-annotation sources. * * @since 2.9 */ public static class Value implements JacksonAnnotationValue, java.io.Serializable { private static final long serialVersionUID = 1L; protected final static Value EMPTY = new Value(null, null); /** * Id to use to access injected value; if `null`, "default" name, derived * from accessor will be used. */ protected final Object _id; protected final Boolean _useInput; protected Value(Object id, Boolean useInput) { _id = id; _useInput = useInput; } @Override public Class valueFor() { return JacksonInject.class; } /* /********************************************************** /* Factory methods /********************************************************** */ public static Value empty() { return EMPTY; } public static Value construct(Object id, Boolean useInput) { if ("".equals(id)) { id = null; } if (_empty(id, useInput)) { return EMPTY; } return new Value(id, useInput); } public static Value from(JacksonInject src) { if (src == null) { return EMPTY; } return construct(src.value(), src.useInput().asBoolean()); } public static Value forId(Object id) { return construct(id, null); } /* /********************************************************** /* Mutant factory methods /********************************************************** */ public Value withId(Object id) { if (id == null) { if (_id == null) { return this; } } else if (id.equals(_id)) { return this; } return new Value(id, _useInput); } public Value withUseInput(Boolean useInput) { if (useInput == null) { if (_useInput == null) { return this; } } else if (useInput.equals(_useInput)) { return this; } return new Value(_id, useInput); } /* /********************************************************** /* Accessors /********************************************************** */ public Object getId() { return _id; } public Boolean getUseInput() { return _useInput; } public boolean hasId() { return _id != null; } public boolean willUseInput(boolean defaultSetting) { return (_useInput == null) ? defaultSetting : _useInput.booleanValue(); } /* /********************************************************** /* Std method overrides /********************************************************** */ @Override public String toString() { return String.format("JacksonInject.Value(id=%s,useInput=%s)", _id, _useInput); } @Override public int hashCode() { int h = 1; if (_id != null) { h += _id.hashCode(); } if (_useInput != null) { h += _useInput.hashCode(); } return h; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() == getClass()) { Value other = (Value) o; if (OptBoolean.equals(_useInput, other._useInput)) { if (_id == null) { return other._id == null; } return _id.equals(other._id); } } return false; } /* /********************************************************** /* Other /********************************************************** */ private static boolean _empty(Object id, Boolean useInput) { return (id == null) && (useInput == null); } } } JsonAlias.java000066400000000000000000000020321323177441000351610ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation that can be used to define one or more alternative names for * a property, accepted during deserialization as alternative to the official * name. Alias information is also exposed during POJO introspection, but has * no effect during serialization where primary name is always used. *

* Examples: *

 *public class Info {
 *  @JsonAlias({ "n", "Name" })
 *  public String name;
 *}
 *
* * @since 2.9 */ @Target({ElementType.ANNOTATION_TYPE, // for combo-annotations ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER// for properties (field, setter, ctor param) }) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonAlias { /** * One or more secondary names to accept as aliases to the official name. */ public String[] value() default { }; } JsonAnyGetter.java000066400000000000000000000026201323177441000360350ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that can be used to define a non-static, * no-argument method to be an "any getter"; accessor for getting * a set of key/value pairs, to be serialized as part of containing POJO * (similar to unwrapping) along with regular property values it has. * This typically serves as a counterpart * to "any setter" mutators (see {@link JsonAnySetter}). * Note that the return type of annotated methods must be * {@link java.util.Map}). *

* As with {@link JsonAnySetter}, only one property should be annotated * with this annotation; if multiple methods are annotated, an exception * may be thrown. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonAnyGetter { /** * Optional argument that defines whether this annotation is active * or not. The only use for value 'false' if for overriding purposes. * Overriding may be necessary when used * with "mix-in annotations" (aka "annotation overrides"). * For most cases, however, default value of "true" is just fine * and should be omitted. * * @since 2.9 */ boolean enabled() default true; } JsonAnySetter.java000066400000000000000000000027731323177441000360620ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that can be used to define a logical "any setter" mutator -- * either using non-static * two-argument method (first argument name of property, second value * to set) or a field (of type {@link java.util.Map} or POJO) - * to be used as a "fallback" handler * for all otherwise unrecognized properties found from JSON content. * It is similar to {@link javax.xml.bind.annotation.XmlAnyElement} * in behavior; and can only be used to denote a single property * per type. *

* If used, all otherwise unmapped key-value pairs from JSON Object values * are added using mutator. *

* NOTE: ability to annotated fields was added in version 2.8; earlier only * methods could be annotated. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonAnySetter { /** * Optional argument that defines whether this annotation is active * or not. The only use for value 'false' if for overriding purposes. * Overriding may be necessary when used * with "mix-in annotations" (aka "annotation overrides"). * For most cases, however, default value of "true" is just fine * and should be omitted. * * @since 2.9 */ boolean enabled() default true; } JsonAutoDetect.java000066400000000000000000000335171323177441000362050ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.*; import java.lang.reflect.Member; import java.lang.reflect.Modifier; /** * Class annotation that can be used to define which kinds of Methods * are to be detected by auto-detection, and with what minimum access level. * Auto-detection means using name conventions * and/or signature templates to find methods to use for data binding. * For example, so-called "getters" can be auto-detected by looking for * public member methods that return a value, do not take argument, * and have prefix "get" in their name. *

* Default setting for all accessors is {@link Visibility#DEFAULT}, which * in turn means that the global defaults are used. Defaults * are different for different accessor types (getters need to be public; * setters can have any access modifier, for example). * If you assign different {@link Visibility} type then it will override * global defaults: for example, to require that all setters must be public, * you would use: *

 *   @JsonAutoDetect(setterVisibility=Visibility.PUBLIC_ONLY)
 *
*/ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonAutoDetect { /** * Enumeration for possible visibility thresholds (minimum visibility) * that can be used to limit which methods (and fields) are * auto-detected. */ public enum Visibility { /** * Value that means that all kinds of access modifiers are acceptable, * from private to public. */ ANY, /** * Value that means that any other access modifier other than 'private' * is considered auto-detectable. */ NON_PRIVATE, /** * Value that means access modifiers 'protected' and 'public' are * auto-detectable (and 'private' and "package access" == no modifiers * are not) */ PROTECTED_AND_PUBLIC, /** * Value to indicate that only 'public' access modifier is considered * auto-detectable. */ PUBLIC_ONLY, /** * Value that indicates that no access modifiers are auto-detectable: * this can be used to explicitly disable auto-detection for specified * types. */ NONE, /** * Value that indicates that default visibility level (whatever it is, * depends on context) is to be used. This usually means that inherited * value (from parent visibility settings) is to be used. */ DEFAULT; public boolean isVisible(Member m) { switch (this) { case ANY: return true; case NONE: return false; case NON_PRIVATE: return !Modifier.isPrivate(m.getModifiers()); case PROTECTED_AND_PUBLIC: if (Modifier.isProtected(m.getModifiers())) { return true; } // fall through to public case: case PUBLIC_ONLY: return Modifier.isPublic(m.getModifiers()); default: return false; } } } /** * Minimum visibility required for auto-detecting regular getter methods. */ Visibility getterVisibility() default Visibility.DEFAULT; /** * Minimum visibility required for auto-detecting is-getter methods. */ Visibility isGetterVisibility() default Visibility.DEFAULT; /** * Minimum visibility required for auto-detecting setter methods. */ Visibility setterVisibility() default Visibility.DEFAULT; /** * Minimum visibility required for auto-detecting Creator methods, * except for no-argument constructors (which are always detected * no matter what). */ Visibility creatorVisibility() default Visibility.DEFAULT; /** * Minimum visibility required for auto-detecting member fields. */ Visibility fieldVisibility() default Visibility.DEFAULT; /* /********************************************************** /* Value class used to enclose information, allow for /* merging of layered configuration settings. /********************************************************** */ /** * Helper class used to contain information from a single {@link JsonIgnoreProperties} * annotation, as well as to provide possible overrides from non-annotation sources. * * @since 2.9 */ public static class Value implements JacksonAnnotationValue, java.io.Serializable { private static final long serialVersionUID = 1L; private final static Visibility DEFAULT_FIELD_VISIBILITY = Visibility.PUBLIC_ONLY; /** * Default instance with baseline visibility checking: *
    *
  • Only public fields visible
  • *
  • Only public getters, is-getters visible
  • *
  • All setters (regardless of access) visible
  • *
  • Only public Creators visible
  • *
*/ protected final static Value DEFAULT = new Value(DEFAULT_FIELD_VISIBILITY, Visibility.PUBLIC_ONLY, Visibility.PUBLIC_ONLY, Visibility.ANY, Visibility.PUBLIC_ONLY); /** * Empty instance that specifies no overrides, that is, all visibility * levels set as {@link Visibility#DEFAULT}. */ protected final static Value NO_OVERRIDES = new Value(Visibility.DEFAULT, Visibility.DEFAULT, Visibility.DEFAULT, Visibility.DEFAULT, Visibility.DEFAULT); protected final Visibility _fieldVisibility; protected final Visibility _getterVisibility; protected final Visibility _isGetterVisibility; protected final Visibility _setterVisibility; protected final Visibility _creatorVisibility; private Value(Visibility fields, Visibility getters, Visibility isGetters, Visibility setters, Visibility creators) { _fieldVisibility = fields; _getterVisibility = getters; _isGetterVisibility = isGetters; _setterVisibility = setters; _creatorVisibility = creators; } public static Value defaultVisibility() { return DEFAULT; } public static Value noOverrides() { return NO_OVERRIDES; } public static Value from(JsonAutoDetect src) { return construct(src.fieldVisibility(), src.getterVisibility(), src.isGetterVisibility(), src.setterVisibility(), src.creatorVisibility()); } /** * Factory method for cnstructing instance with visibility of specified accessor * (or, in case of ALL, all of them) set as specified; and the * rest (if any) set as {@link Visibility#DEFAULT}). */ public static Value construct(PropertyAccessor acc, Visibility visibility) { Visibility fields = Visibility.DEFAULT; Visibility getters = Visibility.DEFAULT; Visibility isGetters = Visibility.DEFAULT; Visibility setters = Visibility.DEFAULT; Visibility creators = Visibility.DEFAULT; switch (acc) { case CREATOR: creators = visibility; break; case FIELD: fields = visibility; break; case GETTER: getters = visibility; break; case IS_GETTER: isGetters = visibility; break; case NONE: break; case SETTER: setters = visibility; break; case ALL: // default fields = getters = isGetters = setters = creators = visibility; break; } return construct(fields, getters, isGetters, setters, creators); } public static Value construct(Visibility fields, Visibility getters, Visibility isGetters, Visibility setters, Visibility creators) { Value v = _predefined(fields, getters, isGetters, setters, creators); if (v == null) { v = new Value(fields, getters, isGetters, setters, creators); } return v; } public Value withFieldVisibility(Visibility v) { return construct(v, _getterVisibility, _isGetterVisibility, _setterVisibility, _creatorVisibility); } public Value withGetterVisibility(Visibility v) { return construct(_fieldVisibility, v, _isGetterVisibility, _setterVisibility, _creatorVisibility); } public Value withIsGetterVisibility(Visibility v) { return construct(_fieldVisibility, _getterVisibility, v, _setterVisibility, _creatorVisibility); } public Value withSetterVisibility(Visibility v) { return construct(_fieldVisibility, _getterVisibility, _isGetterVisibility, v, _creatorVisibility); } public Value withCreatorVisibility(Visibility v) { return construct(_fieldVisibility, _getterVisibility, _isGetterVisibility, _setterVisibility, v); } public static Value merge(Value base, Value overrides) { return (base == null) ? overrides : base.withOverrides(overrides); } public Value withOverrides(Value overrides) { if ((overrides == null) || (overrides == NO_OVERRIDES) || (overrides == this)) { return this; } if (_equals(this, overrides)) { return this; } Visibility fields = overrides._fieldVisibility; if (fields == Visibility.DEFAULT) { fields = _fieldVisibility; } Visibility getters = overrides._getterVisibility; if (getters == Visibility.DEFAULT) { getters = _getterVisibility; } Visibility isGetters = overrides._isGetterVisibility; if (isGetters == Visibility.DEFAULT) { isGetters = _isGetterVisibility; } Visibility setters = overrides._setterVisibility; if (setters == Visibility.DEFAULT) { setters = _setterVisibility; } Visibility creators = overrides._creatorVisibility; if (creators == Visibility.DEFAULT) { creators = _creatorVisibility; } return construct(fields, getters, isGetters, setters, creators); } @Override public Class valueFor() { return JsonAutoDetect.class; } public Visibility getFieldVisibility() { return _fieldVisibility; } public Visibility getGetterVisibility() { return _getterVisibility; } public Visibility getIsGetterVisibility() { return _isGetterVisibility; } public Visibility getSetterVisibility() { return _setterVisibility; } public Visibility getCreatorVisibility() { return _creatorVisibility; } // for JDK serialization protected Object readResolve() { Value v = _predefined(_fieldVisibility, _getterVisibility, _isGetterVisibility, _setterVisibility, _creatorVisibility); return (v == null) ? this : v; } @Override public String toString() { return String.format( "JsonAutoDetect.Value(fields=%s,getters=%s,isGetters=%s,setters=%s,creators=%s)", _fieldVisibility, _getterVisibility, _isGetterVisibility, _setterVisibility, _creatorVisibility ); } @Override public int hashCode() { return 1 + _fieldVisibility.ordinal() ^ (3 * _getterVisibility.ordinal()) - (7 * _isGetterVisibility.ordinal()) + (11 * _setterVisibility.ordinal()) ^ (13 * _creatorVisibility.ordinal()) ; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; return (o.getClass() == getClass()) && _equals(this, (Value) o); } private static Value _predefined(Visibility fields, Visibility getters, Visibility isGetters, Visibility setters, Visibility creators) { if (fields == DEFAULT_FIELD_VISIBILITY) { if ((getters == DEFAULT._getterVisibility) && (isGetters == DEFAULT._isGetterVisibility) && (setters == DEFAULT._setterVisibility) && (creators == DEFAULT._creatorVisibility)) { return DEFAULT; } } else if (fields == Visibility.DEFAULT) { if ((getters == Visibility.DEFAULT) && (isGetters == Visibility.DEFAULT) && (setters == Visibility.DEFAULT) && (creators == Visibility.DEFAULT)) { return NO_OVERRIDES; } } return null; } private static boolean _equals(Value a, Value b) { return (a._fieldVisibility == b._fieldVisibility) && (a._getterVisibility == b._getterVisibility) && (a._isGetterVisibility == b._isGetterVisibility) && (a._setterVisibility == b._setterVisibility) && (a._creatorVisibility == b._creatorVisibility) ; } } } JsonBackReference.java000066400000000000000000000033151323177441000366140ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to indicate that associated property is part of * two-way linkage between fields; and that its role is "child" (or "back") link. * Value type of the property must be a bean: it can not be a Collection, Map, * Array or enumeration. * Linkage is handled such that the property * annotated with this annotation is not serialized; and during deserialization, * its value is set to instance that has the "managed" (forward) link. *

* All references have logical name to allow handling multiple linkages; typical case * would be that where nodes have both parent/child and sibling linkages. If so, * pairs of references should be named differently. * It is an error for a class to have multiple back references with same name, * even if types pointed are different. *

* Note: only methods and fields can be annotated with this annotation: constructor * arguments should NOT be annotated, as they can not be either managed or back * references. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonBackReference { /** * Logical have for the reference property pair; used to link managed and * back references. Default name can be used if there is just single * reference pair (for example, node class that just has parent/child linkage, * consisting of one managed reference and matching back reference) */ public String value() default "defaultReference"; } JsonClassDescription.java000066400000000000000000000013111323177441000374000ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to define a human readable description for annotated * type (class). * Currently used to populate the description field in generated JSON * Schemas. * * @since 2.7 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @JacksonAnnotation public @interface JsonClassDescription { /** * Defines a human readable description of the class. */ String value() default ""; } JsonCreator.java000066400000000000000000000101751323177441000355360ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that can be used to define constructors and factory * methods as one to use for instantiating new instances of the associated * class. *

* NOTE: when annotating creator methods (constructors, factory methods), * method must either be: *

    *
  • Single-argument constructor/factory method without {@link JsonProperty} * annotation for the argument: if so, this is so-called "delegate creator", * in which case Jackson first binds JSON into type of the argument, and * then calls creator. This is often used in conjunction with {@link JsonValue} * (used for serialization). *
  • *
  • Constructor/factory method where every argument is annotated with * either {@link JsonProperty} or {@link JacksonInject}, to indicate name * of property to bind to *
  • *
* Also note that all {@link JsonProperty} annotations must specify actual name * (NOT empty String for "default") unless you use one of extension modules * that can detect parameter name; this because default JDK versions before 8 * have not been able to store and/or retrieve parameter names from bytecode. * But with JDK 8 (or using helper libraries such as Paranamer, or other JVM * languages like Scala or Kotlin), specifying name is optional. *

* One common use case is to use a delegating Creator to construct instances from * scalar values (like java.lang.String) during deserialization, * and serialize values using {@link JsonValue}. *

* NOTE: As of Jackson 2.6, use of {@link JsonProperty#required()} is supported * for Creator methods (but not necessarily for regular setters or fields!). * * @see JsonCreator */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonCreator { /** * Property that is used to indicate how argument(s) is/are bound for creator, * in cases there may be multiple alternatives. Currently the one case is that * of a single-argument creator method, for which both so-called "delegating" and * "property-based" bindings are possible: since * delegating mode can not be used for multi-argument creators, the only choice * there is "property-based" mode. * Check {@link Mode} for more complete explanation of possible choices. *

* Default value of {@link Mode#DEFAULT} means that caller is to use standard * heuristics for choosing mode to use. * * @since 2.5 */ public Mode mode() default Mode.DEFAULT; /** * @since 2.5 */ public enum Mode { /** * Pseudo-mode that indicates that caller is to use default heuristics for * choosing mode to use. This typically favors use of delegating mode for * single-argument creators that take structured types. */ DEFAULT, /** * Mode that indicates that if creator takes a single argument, the whole incoming * data value is to be bound into declared type of that argument; this "delegate" * value is then passed as the argument to creator. */ DELEGATING, /** * Mode that indicates that the argument(s) for creator are to be bound from matching * properties of incoming Object value, using creator argument names (explicit or implicit) * to match incoming Object properties to arguments. *

* Note that this mode is currently (2.5) always used for multiple-argument creators; * the only ambiguous case is that of a single-argument creator. */ PROPERTIES, /** * Pseudo-mode that indicates that creator is not to be used. This can be used as a result * value for explicit disabling, usually either by custom annotation introspector, * or by annotation mix-ins (for example when choosing different creator). */ DISABLED } } JsonEnumDefaultValue.java000066400000000000000000000013761323177441000373500ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that can be used to define a default value * used when trying to deserialize unknown Enum values. *

* This annotation is only applicable when the @READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE * deserialization feature is enabled. *

* If the more than one enum value is marked with this annotation, * the first one to be detected will be used. Which one exactly is undetermined. */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonEnumDefaultValue { } JsonFilter.java000066400000000000000000000023111323177441000353550ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to indicate which logical filter is to be used * for filtering out properties of type (class) annotated; * association made by this annotation declaring ids of filters, * and com.fasterxml.jackson.databind.ObjectMapper (or objects * it delegates to) providing matching filters by id. *

* Filters to use are usually of type * com.fasterxml.jackson.databind.ser.BeanPropertyFilter and * are registered through com.fasterxml.jackson.databind.ObjectMapper *

* Since 2.3, this annotation can also be used on properties (fields, methods, * constructor parameters). */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER // new in 2.3 }) @Retention(RetentionPolicy.RUNTIME) @com.fasterxml.jackson.annotation.JacksonAnnotation public @interface JsonFilter { /** * Id of filter to use; if empty String (""), no filter is to be used. */ public String value(); } JsonFormat.java000066400000000000000000000674471323177441000354050ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.*; import java.util.Locale; import java.util.TimeZone; /** * General-purpose annotation used for configuring details of how * values of properties are to be serialized. * Unlike most other Jackson annotations, annotation does not * have specific universal interpretation: instead, effect depends on datatype * of property being annotated (or more specifically, deserializer * and serializer being used). *

* Common uses include choosing between alternate representations -- for example, * whether {@link java.util.Date} is to be serialized as number (Java timestamp) * or String (such as ISO-8601 compatible time value) -- as well as configuring * exact details with {@link #pattern} property. *

* As of Jackson 2.6, known special handling includes: *

    *
  • {@link java.util.Date}: Shape can be {@link Shape#STRING} or {@link Shape#NUMBER}; * pattern may contain {@link java.text.SimpleDateFormat}-compatible pattern definition. *
  • *
  • Can be used on Classes (types) as well, for modified default behavior, possibly * overridden by per-property annotation *
  • *
  • {@link java.lang.Enum}s: Shapes {@link Shape#STRING} and {@link Shape#NUMBER} can be * used to change between numeric (index) and textual (name or toString()); * but it is also possible to use {@link Shape#OBJECT} to serialize (but not deserialize) * {@link java.lang.Enum}s as JSON Objects (as if they were POJOs). NOTE: serialization * as JSON Object only works with class annotation; * will not work as per-property annotation. *
  • *
  • {@link java.util.Collection}s can be serialized as (and deserialized from) JSON Objects, * if {@link Shape#OBJECT} is used. NOTE: can ONLY be used as class annotation; * will not work as per-property annotation. *
  • *
  • {@link java.lang.Number} subclasses can be serialized as full objects if * {@link Shape#OBJECT} is used. Otherwise the default behavior of serializing to a * scalar number value will be preferred. NOTE: can ONLY be used as class annotation; * will not work as per-property annotation. *
  • *
* * @since 2.0 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonFormat { /** * Value that indicates that default {@link java.util.Locale} * (from deserialization or serialization context) should be used: * annotation does not define value to use. */ public final static String DEFAULT_LOCALE = "##default"; /** * Value that indicates that default {@link java.util.TimeZone} * (from deserialization or serialization context) should be used: * annotation does not define value to use. *

* NOTE: default here does NOT mean JVM defaults but Jackson databindings * default, usually UTC, but may be changed on ObjectMapper. */ public final static String DEFAULT_TIMEZONE = "##default"; /** * Datatype-specific additional piece of configuration that may be used * to further refine formatting aspects. This may, for example, determine * low-level format String used for {@link java.util.Date} serialization; * however, exact use is determined by specific JsonSerializer */ public String pattern() default ""; /** * Structure to use for serialization: definition of mapping depends on datatype, * but usually has straight-forward counterpart in data format (JSON). * Note that commonly only a subset of shapes is available; and if 'invalid' value * is chosen, defaults are usually used. */ public Shape shape() default Shape.ANY; /** * {@link java.util.Locale} to use for serialization (if needed). * Special value of {@link #DEFAULT_LOCALE} * can be used to mean "just use the default", where default is specified * by the serialization context, which in turn defaults to system * defaults ({@link java.util.Locale#getDefault()}) unless explicitly * set to another locale. */ public String locale() default DEFAULT_LOCALE; /** * {@link java.util.TimeZone} to use for serialization (if needed). * Special value of {@link #DEFAULT_TIMEZONE} * can be used to mean "just use the default", where default is specified * by the serialization context, which in turn defaults to system * default (UTC) unless explicitly set to another timezone. */ public String timezone() default DEFAULT_TIMEZONE; /** * Property that indicates whether "lenient" handling should be enabled or * disabled. This is relevant mostly for deserialization of some textual * datatypes, especially date/time types. *

* Note that underlying default setting depends on datatype (or more precisely * deserializer for it): for most date/time types, default is for leniency * to be enabled. * * @since 2.9 */ public OptBoolean lenient() default OptBoolean.DEFAULT; /** * Set of {@link JsonFormat.Feature}s to explicitly enable with respect * to handling of annotated property. This will have precedence over possible * global configuration. * * @since 2.6 */ public JsonFormat.Feature[] with() default { }; /** * Set of {@link JsonFormat.Feature}s to explicitly disable with respect * to handling of annotated property. This will have precedence over possible * global configuration. * * @since 2.6 */ public JsonFormat.Feature[] without() default { }; /* /********************************************************** /* Value enumeration(s), value class(es) /********************************************************** */ /** * Value enumeration used for indicating preferred Shape; translates * loosely to JSON types, with some extra values to indicate less precise * choices (i.e. allowing one of multiple actual shapes) */ public enum Shape { /** * Marker enum value that indicates "whatever" choice, meaning that annotation * does NOT specify shape to use. * Note that this is different from {@link Shape#NATURAL}, which * specifically instructs use of the "natural" shape for datatype. */ ANY, /** * Marker enum value that indicates the "default" choice for given datatype; * for example, JSON String for {@link java.lang.String}, or JSON Number * for Java numbers. * Note that this is different from {@link Shape#ANY} in that this is actual * explicit choice that overrides possible default settings. * * @since 2.8 */ NATURAL, /** * Value that indicates shape should not be structural (that is, not * {@link #ARRAY} or {@link #OBJECT}, but can be any other shape. */ SCALAR, /** * Value that indicates that (JSON) Array type should be used. */ ARRAY, /** * Value that indicates that (JSON) Object type should be used. */ OBJECT, /** * Value that indicates that a numeric (JSON) type should be used * (but does not specify whether integer or floating-point representation * should be used) */ NUMBER, /** * Value that indicates that floating-point numeric type should be used */ NUMBER_FLOAT, /** * Value that indicates that integer number type should be used * (and not {@link #NUMBER_FLOAT}). */ NUMBER_INT, /** * Value that indicates that (JSON) String type should be used. */ STRING, /** * Value that indicates that (JSON) boolean type * (true, false) should be used. */ BOOLEAN ; public boolean isNumeric() { return (this == NUMBER) || (this == NUMBER_INT) || (this == NUMBER_FLOAT); } public boolean isStructured() { return (this == OBJECT) || (this == ARRAY); } } /** * Set of features that can be enabled/disabled for property annotated. * These often relate to specific SerializationFeature * or DeserializationFeature, as noted by entries. *

* Note that whether specific setting has an effect depends on whether * JsonSerializer / JsonDeserializer being used * takes the format setting into account. If not, please file an issue * for adding support via issue tracker for package that has handlers * (if you know which one; if not, just use `jackson-databind`). * * @since 2.6 */ public enum Feature { /** * Override for DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY * which will allow deserialization of JSON non-array values into single-element * Java arrays and {@link java.util.Collection}s. */ ACCEPT_SINGLE_VALUE_AS_ARRAY, /** * Override for MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES. * Only affects deserialization, has no effect on serialization. *

* NOTE: starting with 2.9 can also effect Enum handling (and potentially other * places where case-insensitive property values are accepted). * * @since 2.8 */ ACCEPT_CASE_INSENSITIVE_PROPERTIES, /** * Override for SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, * similar constraints apply. */ WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, /** * Override for SerializationFeature.WRITE_DATES_WITH_ZONE_ID, * similar constraints apply. */ WRITE_DATES_WITH_ZONE_ID, /** * Override for SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED * which will force serialization of single-element arrays and {@link java.util.Collection}s * as that single element and excluding array wrapper. */ WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, /** * Override for SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, * enabling of which will force sorting of {@link java.util.Map} keys before * serialization. */ WRITE_SORTED_MAP_ENTRIES, /** * Override for DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIMEZONE * that specifies whether context provided timezone * DeserializationContext.getTimeZone() should be used to adjust Date/Time * values on deserialization, even if value itself contains timezone informatio *

* NOTE: due to limitations of "old" JDK date/time types (that is, * {@link java.util.Date} and {@link java.util.Calendar}), this setting is only * applicable to Joda and Java 8 date/time values, * but not to java.util.Date or java.util.Calendar. * * @since 2.8 */ ADJUST_DATES_TO_CONTEXT_TIME_ZONE } /** * Helper class that encapsulates information equivalent to {@link java.lang.Boolean} * valued {@link java.util.EnumMap}. * * @since 2.6 */ public static class Features { private final int _enabled, _disabled; private final static Features EMPTY = new Features(0, 0); private Features(int e, int d) { _enabled = e; _disabled = d; } public static Features empty() { return EMPTY; } public static Features construct(JsonFormat f) { return construct(f.with(), f.without()); } public static Features construct(Feature[] enabled, Feature[] disabled) { int e = 0; for (Feature f : enabled) { e |= (1 << f.ordinal()); } int d = 0; for (Feature f : disabled) { d |= (1 << f.ordinal()); } return new Features(e, d); } public Features withOverrides(Features overrides) { // Cheap checks first: maybe one is empty? if (overrides == null) { return this; } int overrideD = overrides._disabled; int overrideE = overrides._enabled; if ((overrideD == 0) && (overrideE == 0)) { return this; } if ((_enabled == 0) && (_disabled == 0)) { return overrides; } // If not, calculate combination with overrides int newE = (_enabled & ~overrideD) | overrideE; int newD = (_disabled & ~overrideE) | overrideD; // one more thing; no point in creating new instance if there's no change if ((newE == _enabled) && (newD == _disabled)) { return this; } return new Features(newE, newD); } public Features with(Feature...features) { int e = _enabled; for (Feature f : features) { e |= (1 << f.ordinal()); } return (e == _enabled) ? this : new Features(e, _disabled); } public Features without(Feature...features) { int d = _disabled; for (Feature f : features) { d |= (1 << f.ordinal()); } return (d == _disabled) ? this : new Features(_enabled, d); } public Boolean get(Feature f) { int mask = (1 << f.ordinal()); if ((_disabled & mask) != 0) { return Boolean.FALSE; } if ((_enabled & mask) != 0) { return Boolean.TRUE; } return null; } @Override public String toString() { if (this == EMPTY) { return "EMPTY"; } return String.format("(enabled=0x%x,disabled=0x%x)", _enabled, _disabled); } @Override public int hashCode() { return _disabled + _enabled; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) return false; Features other = (Features) o; return (other._enabled == _enabled) && (other._disabled == _disabled); } } /** * Helper class used to contain information from a single {@link JsonFormat} * annotation. */ public static class Value implements JacksonAnnotationValue, // since 2.6 java.io.Serializable { private static final long serialVersionUID = 1L; private final static Value EMPTY = new Value(); private final String _pattern; private final Shape _shape; private final Locale _locale; private final String _timezoneStr; /** * @since 2.9 */ private final Boolean _lenient; /** * @since 2.6 */ private final Features _features; // lazily constructed when created from annotations private transient TimeZone _timezone; public Value() { this("", Shape.ANY, "", "", Features.empty(), null); } public Value(JsonFormat ann) { this(ann.pattern(), ann.shape(), ann.locale(), ann.timezone(), Features.construct(ann), ann.lenient().asBoolean()); } /** * @since 2.9 */ public Value(String p, Shape sh, String localeStr, String tzStr, Features f, Boolean lenient) { this(p, sh, (localeStr == null || localeStr.length() == 0 || DEFAULT_LOCALE.equals(localeStr)) ? null : new Locale(localeStr), (tzStr == null || tzStr.length() == 0 || DEFAULT_TIMEZONE.equals(tzStr)) ? null : tzStr, null, f, lenient); } /** * @since 2.9 */ public Value(String p, Shape sh, Locale l, TimeZone tz, Features f, Boolean lenient) { _pattern = p; _shape = (sh == null) ? Shape.ANY : sh; _locale = l; _timezone = tz; _timezoneStr = null; _features = (f == null) ? Features.empty() : f; _lenient = lenient; } /** * @since 2.9 */ public Value(String p, Shape sh, Locale l, String tzStr, TimeZone tz, Features f, Boolean lenient) { _pattern = p; _shape = (sh == null) ? Shape.ANY : sh; _locale = l; _timezone = tz; _timezoneStr = tzStr; _features = (f == null) ? Features.empty() : f; _lenient = lenient; } @Deprecated // since 2.9 public Value(String p, Shape sh, Locale l, String tzStr, TimeZone tz, Features f) { this(p, sh, l, tzStr, tz, f, null); } @Deprecated // since 2.9 public Value(String p, Shape sh, String localeStr, String tzStr, Features f) { this(p, sh, localeStr, tzStr, f, null); } @Deprecated // since 2.9 public Value(String p, Shape sh, Locale l, TimeZone tz, Features f) { this(p, sh, l, tz, f, null); } /** * @since 2.7 */ public final static Value empty() { return EMPTY; } /** * Helper method that will try to combine values from two {@link Value} * instances, using one as base settings, and the other as overrides * to use instead of base values when defined; base values are only * use if override does not specify a value (matching value is null * or logically missing). * Note that one or both of value instances may be `null`, directly; * if both are `null`, result will also be `null`; otherwise never null. * * @since 2.8 */ public static Value merge(Value base, Value overrides) { return (base == null) ? overrides : base.withOverrides(overrides); } /** * @since 2.8 */ public static Value mergeAll(Value... values) { Value result = null; for (Value curr : values) { if (curr != null) { result = (result == null) ? curr : result.withOverrides(curr); } } return result; } /** * @since 2.7 */ public final static Value from(JsonFormat ann) { return (ann == null) ? EMPTY : new Value(ann); } /** * @since 2.7 */ public final Value withOverrides(Value overrides) { if ((overrides == null) || (overrides == EMPTY) || (overrides == this)) { return this; } if (this == EMPTY) { // cheesy, but probably common enough return overrides; } String p = overrides._pattern; if ((p == null) || p.isEmpty()) { p = _pattern; } Shape sh = overrides._shape; if (sh == Shape.ANY) { sh = _shape; } Locale l = overrides._locale; if (l == null) { l = _locale; } Features f = _features; if (f == null) { f = overrides._features; } else { f = f.withOverrides(overrides._features); } Boolean lenient = overrides._lenient; if (lenient == null) { lenient = _lenient; } // timezone not merged, just choose one String tzStr = overrides._timezoneStr; TimeZone tz; if ((tzStr == null) || tzStr.isEmpty()) { // no overrides, use space tzStr = _timezoneStr; tz = _timezone; } else { tz = overrides._timezone; } return new Value(p, sh, l, tzStr, tz, f, lenient); } /** * @since 2.6 */ public static Value forPattern(String p) { return new Value(p, null, null, null, null, Features.empty(), null); } /** * @since 2.7 */ public static Value forShape(Shape sh) { return new Value(null, sh, null, null, null, Features.empty(), null); } /** * @since 2.9 */ public static Value forLeniency(boolean lenient) { return new Value(null, null, null, null, null, Features.empty(), Boolean.valueOf(lenient)); } /** * @since 2.1 */ public Value withPattern(String p) { return new Value(p, _shape, _locale, _timezoneStr, _timezone, _features, _lenient); } /** * @since 2.1 */ public Value withShape(Shape s) { if (s == _shape) { return this; } return new Value(_pattern, s, _locale, _timezoneStr, _timezone, _features, _lenient); } /** * @since 2.1 */ public Value withLocale(Locale l) { return new Value(_pattern, _shape, l, _timezoneStr, _timezone, _features, _lenient); } /** * @since 2.1 */ public Value withTimeZone(TimeZone tz) { return new Value(_pattern, _shape, _locale, null, tz, _features, _lenient); } /** * @since 2.9 */ public Value withLenient(Boolean lenient) { if (lenient == _lenient) { return this; } return new Value(_pattern, _shape, _locale, _timezoneStr, _timezone, _features, lenient); } /** * @since 2.6 */ public Value withFeature(JsonFormat.Feature f) { Features newFeats = _features.with(f); return (newFeats == _features) ? this : new Value(_pattern, _shape, _locale, _timezoneStr, _timezone, newFeats, _lenient); } /** * @since 2.6 */ public Value withoutFeature(JsonFormat.Feature f) { Features newFeats = _features.without(f); return (newFeats == _features) ? this : new Value(_pattern, _shape, _locale, _timezoneStr, _timezone, newFeats, _lenient); } @Override public Class valueFor() { return JsonFormat.class; } public String getPattern() { return _pattern; } public Shape getShape() { return _shape; } public Locale getLocale() { return _locale; } /** * @since 2.9 */ public Boolean getLenient() { return _lenient; } /** * @since 2.9 */ public boolean isLenient() { return Boolean.TRUE.equals(_lenient); } /** * Alternate access (compared to {@link #getTimeZone()}) which is useful * when caller just wants time zone id to convert, but not as JDK * provided {@link TimeZone} * * @since 2.4 */ public String timeZoneAsString() { if (_timezone != null) { return _timezone.getID(); } return _timezoneStr; } public TimeZone getTimeZone() { TimeZone tz = _timezone; if (tz == null) { if (_timezoneStr == null) { return null; } tz = TimeZone.getTimeZone(_timezoneStr); _timezone = tz; } return tz; } /** * @since 2.4 */ public boolean hasShape() { return _shape != Shape.ANY; } /** * @since 2.4 */ public boolean hasPattern() { return (_pattern != null) && (_pattern.length() > 0); } /** * @since 2.4 */ public boolean hasLocale() { return _locale != null; } /** * @since 2.4 */ public boolean hasTimeZone() { return (_timezone != null) || (_timezoneStr != null && !_timezoneStr.isEmpty()); } /** * Accessor for checking whether there is a setting for leniency. * NOTE: does NOT mean that `lenient` is `true` necessarily; just that * it has been set. * * @since 2.9 */ public boolean hasLenient() { return _lenient != null; } /** * Accessor for checking whether this format value has specific setting for * given feature. Result is 3-valued with either `null`, {@link Boolean#TRUE} or * {@link Boolean#FALSE}, indicating 'yes/no/dunno' choices, where `null` ("dunno") * indicates that the default handling should be used based on global defaults, * and there is no format override. * * @since 2.6 */ public Boolean getFeature(JsonFormat.Feature f) { return _features.get(f); } /** * Accessor for getting full set of features enabled/disabled. * * @since 2.8 */ public Features getFeatures() { return _features; } @Override public String toString() { return String.format("JsonFormat.Value(pattern=%s,shape=%s,lenient=%s,locale=%s,timezone=%s,features=%s)", _pattern, _shape, _lenient, _locale, _timezoneStr, _features); } @Override public int hashCode() { int hash = (_timezoneStr == null) ? 1 : _timezoneStr.hashCode(); if (_pattern != null) { hash ^= _pattern.hashCode(); } hash += _shape.hashCode(); if (_lenient != null) { hash ^= _lenient.hashCode(); } if (_locale != null) { hash += _locale.hashCode(); } hash ^= _features.hashCode(); return hash; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) return false; Value other = (Value) o; if ((_shape != other._shape) || !_features.equals(other._features)) { return false; } return _equal(_lenient, other._lenient) && _equal(_timezoneStr, other._timezoneStr) && _equal(_pattern, other._pattern) && _equal(_timezone, other._timezone) && _equal(_locale, other._locale); } private static boolean _equal(T value1, T value2) { if (value1 == null) { return (value2 == null); } if (value2 == null) { return false; } return value1.equals(value2); } } } JsonGetter.java000066400000000000000000000022211323177441000353620ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that can be used to define a non-static, * no-argument value-returning (non-void) method to be used as a "getter" * for a logical property. * It can be used as an alternative to more general * {@link JsonProperty} annotation (which is the recommended choice in * general case). *

* Getter means that when serializing Object instance of class that has * this method (possibly inherited from a super class), a call is made * through the method, and return value will be serialized as value of * the property. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonGetter { /** * Defines name of the logical property this * method is used to access ("get"); empty String means that * name should be derived from the underlying method (using * standard Bean name detection rules) */ String value() default ""; } JsonIdentityInfo.java000066400000000000000000000065471323177441000365540ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used for indicating that values of annotated type * or property should be serializing so that instances either * contain additional object identifier (in addition actual object * properties), or as a reference that consists of an object id * that refers to a full serialization. In practice this is done * by serializing the first instance as full object and object * identity, and other references to the object as reference values. *

* There are two main approaches to generating object identifier: * either using a generator (either one of standard ones, or a custom * generator), or using a value of a property. The latter case is * indicated by using a placeholder generator marker * {@link ObjectIdGenerators.PropertyGenerator}; former by using explicit generator. * Object id has to be serialized as a property in case of POJOs; * object identity is currently NOT support for JSON Array types * (Java arrays or Lists) or Java Map types. *

* Finally, note that generator type of {@link ObjectIdGenerators.None} * indicates that no Object Id should be included or used: it is included * to allow suppressing Object Ids using mix-in annotations. * * @since 2.0 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonIdentityInfo { /** * Name of JSON property in which Object Id will reside: also, * if "from property" marker generator is used, identifies * property that will be accessed to get type id. * If a property is used, name must match its external * name (one defined by annotation, or derived from accessor * name as per Java Bean Introspection rules). *

* Default value is @id. */ public String property() default "@id"; /** * Generator to use for producing Object Identifier for objects: * either one of pre-defined generators from * {@link ObjectIdGenerator}, or a custom generator. * Defined as class to instantiate. *

* Note that special type * {@link ObjectIdGenerators.None} * can be used to disable inclusion of Object Ids. */ public Class> generator(); /** * Resolver to use for producing POJO from Object Identifier. *

* Default value is {@link SimpleObjectIdResolver} * * @since 2.4 */ public Class resolver() default SimpleObjectIdResolver.class; /** * Scope is used to define applicability of an Object Id: all ids * must be unique within their scope; where scope is defined * as combination of this value and generator type. * Comparison is simple equivalence, meaning that both type * generator type and scope class must be the same. *

* Scope is used for determining how many generators are needed; * more than one scope is typically only needed if external Object Ids * have overlapping value domains (i.e. are only unique within some * limited scope) */ public Class scope() default Object.class; } JsonIdentityReference.java000066400000000000000000000024101323177441000375400ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Optional annotation that can be used for customizing details of a reference * to Objects for which "Object Identity" is enabled (see {@link JsonIdentityInfo}). * The main use case is that of enforcing use of Object Id even for the first * time an Object is referenced, instead of first instance being serialized * as full POJO. * * @since 2.1 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonIdentityReference { /** * Marker to indicate whether all referenced values are to * be serialized as ids (true); or by serializing the * first encountered reference as POJO and only then as id (false). *

* Note that if value of 'true' is used, deserialization may require * additional contextual information, and possibly using a custom * id resolver -- the default handling may not be sufficient. * * @since 2.1 */ public boolean alwaysAsId() default false; } JsonIgnore.java000066400000000000000000000055731323177441000353700ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that indicates that the logical property that * the accessor (field, getter/setter method or Creator parameter * [of {@link JsonCreator}-annotated constructor or factory method]) * is to be ignored by introspection-based * serialization and deserialization functionality. *

* Annotation only needs to be added to one of the accessors (often * getter method, but may be setter, field or creator parameter), * if the complete removal of the property is desired. * However: if only particular accessor is to be ignored (for example, * when ignoring one of potentially conflicting setter methods), * this can be done by annotating other not-to-be-ignored accessors * with {@link JsonProperty} (or its equivalents). This is considered * so-called "split property" case and allows definitions of * "read-only" (read from input into POJO) and "write-only" (write * in output but ignore on output) *
* NOTE! As Jackson 2.6, there is a new and improved way to define * `read-only` and `write-only` properties, using * {@link JsonProperty#access()} annotation: this is recommended over * use of separate JsonIgnore and {@link JsonProperty} * annotations. *

* For example, a "getter" method that would otherwise denote * a property (like, say, "getValue" to suggest property "value") * to serialize, would be ignored and no such property would * be output unless another annotation defines alternative method to use. *

* When ignoring the whole property, the default behavior if encountering * such property in input is to ignore it without exception; but if there * is a {@link JsonAnySetter} it will be called instead. Either way, * no exception will be thrown. *

* Annotation is usually used just a like a marker annotation, that * is, without explicitly defining 'value' argument (which defaults * to true): but argument can be explicitly defined. * This can be done to override an existing `JsonIgnore` by explicitly * defining one with 'false' argument: either in a sub-class, or by * using "mix-in annotations". */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonIgnore { /** * Optional argument that defines whether this annotation is active * or not. The only use for value 'false' if for overriding purposes * (which is not needed often); most likely it is needed for use * with "mix-in annotations" (aka "annotation overrides"). * For most cases, however, default value of "true" is just fine * and should be omitted. */ boolean value() default true; } JsonIgnoreProperties.java000066400000000000000000000404741323177441000374440ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.*; /** * Annotation that can be used to either suppress serialization of * properties (during serialization), or ignore processing of * JSON properties read (during deserialization). *

* Example: *

 * // to prevent specified fields from being serialized or deserialized
 * // (i.e. not include in JSON output; or being set even if they were included)
 * @JsonIgnoreProperties({ "internalId", "secretKey" })
 * // To ignore any unknown properties in JSON input without exception:
 * @JsonIgnoreProperties(ignoreUnknown=true)
 *
*

* Annotation can be applied both to classes and * to properties. If used for both, actual set will be union of all * ignorals: that is, you can only add properties to ignore, not remove * or override. So you can not remove properties to ignore using * per-property annotation. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonIgnoreProperties { /** * Names of properties to ignore. */ public String[] value() default { }; /** * Property that defines whether it is ok to just ignore any * unrecognized properties during deserialization. * If true, all properties that are unrecognized -- that is, * there are no setters or creators that accept them -- are * ignored without warnings (although handlers for unknown * properties, if any, will still be called) without * exception. *

* Does not have any effect on serialization. */ public boolean ignoreUnknown() default false; /** * Property that can be enabled to allow "getters" to be used (that is, * prevent ignoral of getters for properties listed in {@link #value()}). * This is commonly set to support defining "read-only" properties; ones * for which there is a getter, but no matching setter: in this case, * properties should be ignored for deserialization but NOT serialization. * Another way to think about this setting is that setting it to `true` * will "disable" ignoring of getters. *

* Default value is `false`, which means that getters with matching names * will be ignored. * * @since 2.6 */ public boolean allowGetters() default false; /** * Property that can be enabled to allow "setters" to be used (that is, * prevent ignoral of setters for properties listed in {@link #value()}). * This could be used to specify "write-only" properties; ones * that should not be serialized out, but that may be provided in for * deserialization. * Another way to think about this setting is that setting it to `true` * will "disable" ignoring of setters. *

* Default value is `false`, which means that setters with matching names * will be ignored. * * @since 2.6 */ public boolean allowSetters() default false; /* /********************************************************** /* Value class used to enclose information, allow for /* merging of layered configuration settings. /********************************************************** */ /** * Helper class used to contain information from a single {@link JsonIgnoreProperties} * annotation, as well as to provide possible overrides from non-annotation sources. * * @since 2.8 */ public static class Value implements JacksonAnnotationValue, java.io.Serializable { private static final long serialVersionUID = 1L; /** * Default instance has no explicitly ignored fields, does not ignore unknowns, * does not explicitly allow getters/setters (that is, ignorals apply to both), * but does use merging for combining overrides with base settings */ protected final static Value EMPTY = new Value(Collections.emptySet(), false, false, false, true); /** * Names of properties to ignore. */ protected final Set _ignored; protected final boolean _ignoreUnknown; protected final boolean _allowGetters; protected final boolean _allowSetters; protected final boolean _merge; protected Value(Set ignored, boolean ignoreUnknown, boolean allowGetters, boolean allowSetters, boolean merge) { if (ignored == null) { _ignored = Collections.emptySet(); } else { _ignored = ignored; } _ignoreUnknown = ignoreUnknown; _allowGetters = allowGetters; _allowSetters = allowSetters; _merge = merge; } public static Value from(JsonIgnoreProperties src) { if (src == null) { return EMPTY; // since 2.9 } return construct(_asSet(src.value()), src.ignoreUnknown(), src.allowGetters(), src.allowSetters(), // 27-Apr-2016, tatu: No matching property in annotation because // we don't know how to merge (so no point in pretending it's there) // so choice is arbitrary. Probably will default to `false` fwtw: false); } /** * Factory method that may be used (although is NOT the recommended way) * to construct an instance from a full set of properties. Most users would * be better of starting by {@link #empty()} instance and using `withXxx()`/`withoutXxx()` * methods, as this factory method may need to be changed if new properties * are added in {@link JsonIgnoreProperties} annotation. */ public static Value construct(Set ignored, boolean ignoreUnknown, boolean allowGetters, boolean allowSetters, boolean merge) { if (_empty(ignored, ignoreUnknown, allowGetters, allowSetters, merge)) { return EMPTY; } return new Value(ignored, ignoreUnknown, allowGetters, allowSetters, merge); } /** * Accessor for default instances which has "empty" settings; that is: *

    *
  • No explicitly defined fields to ignore *
  • *
  • Does not ignore unknown fields *
  • *
  • Does not "allow" getters if property ignored (that is, ignorals apply to both setter and getter) *
  • *
  • Does not "allow" setters if property ignored (that is, ignorals apply to both setter and getter) *
  • *
  • Does use merge when combining overrides to base settings, such that `true` settings * for any of the properties results in `true`, and names of fields are combined (union) *
  • *
*/ public static Value empty() { return EMPTY; } /** * Helper method that will try to combine values from two {@link Value} * instances, using one as base settings, and the other as overrides * to use instead of base values when defined; base values are only * use if override does not specify a value (matching value is null * or logically missing). * Note that one or both of value instances may be `null`, directly; * if both are `null`, result will also be `null`; otherwise never null. */ public static Value merge(Value base, Value overrides) { return (base == null) ? overrides : base.withOverrides(overrides); } /** * @since 2.8 */ public static Value mergeAll(Value... values) { Value result = null; for (Value curr : values) { if (curr != null) { result = (result == null) ? curr : result.withOverrides(curr); } } return result; } public static Value forIgnoredProperties(Set propNames) { return EMPTY.withIgnored(propNames); } public static Value forIgnoredProperties(String... propNames) { if (propNames.length == 0) { return EMPTY; } return EMPTY.withIgnored(_asSet(propNames)); } public static Value forIgnoreUnknown(boolean state) { return state ? EMPTY.withIgnoreUnknown() : EMPTY.withoutIgnoreUnknown(); } /** * Mutant factory method that merges values of this value with given override * values, so that any explicitly defined inclusion in overrides has precedence over * settings of this value instance. If no overrides exist will return this * instance; otherwise new {@link Value} with changed inclusion values. */ public Value withOverrides(Value overrides) { if ((overrides == null) || (overrides == EMPTY)) { return this; } // if non merging, we'll actually end up with just the overrides don't we? // (given there's no "use default" value for anything if (!overrides._merge) { return overrides; } if (_equals(this, overrides)) { return this; } // Here's where mergeability needs to be checked Set ignored = _merge(_ignored, overrides._ignored); boolean ignoreUnknown = _ignoreUnknown || overrides._ignoreUnknown; boolean allowGetters = _allowGetters || overrides._allowGetters; boolean allowSetters = _allowSetters || overrides._allowSetters; // must have 'merge=true' to get this far return construct(ignored, ignoreUnknown, allowGetters, allowSetters, true); } public Value withIgnored(Set ignored) { return construct(ignored, _ignoreUnknown, _allowGetters, _allowSetters, _merge); } public Value withIgnored(String... ignored) { return construct(_asSet(ignored), _ignoreUnknown, _allowGetters, _allowSetters, _merge); } public Value withoutIgnored() { return construct(null, _ignoreUnknown, _allowGetters, _allowSetters, _merge); } public Value withIgnoreUnknown() { return _ignoreUnknown ? this : construct(_ignored, true, _allowGetters, _allowSetters, _merge); } public Value withoutIgnoreUnknown() { return !_ignoreUnknown ? this : construct(_ignored, false, _allowGetters, _allowSetters, _merge); } public Value withAllowGetters() { return _allowGetters ? this : construct(_ignored, _ignoreUnknown, true, _allowSetters, _merge); } public Value withoutAllowGetters() { return !_allowGetters ? this : construct(_ignored, _ignoreUnknown, false, _allowSetters, _merge); } public Value withAllowSetters() { return _allowSetters ? this : construct(_ignored, _ignoreUnknown, _allowGetters, true, _merge); } public Value withoutAllowSetters() { return !_allowSetters ? this : construct(_ignored, _ignoreUnknown, _allowGetters, false, _merge); } public Value withMerge() { return _merge ? this : construct(_ignored, _ignoreUnknown, _allowGetters, _allowSetters, true); } public Value withoutMerge() { return !_merge ? this : construct(_ignored, _ignoreUnknown, _allowGetters, _allowSetters, false); } @Override public Class valueFor() { return JsonIgnoreProperties.class; } // for JDK serialization protected Object readResolve() { if (_empty(_ignored, _ignoreUnknown, _allowGetters, _allowSetters, _merge)) { return EMPTY; } return this; } public Set getIgnored() { return _ignored; } /** * Method called to find names of properties to ignore when used for * serialization: functionally * same as {@link #getIgnored} if {@link #getAllowGetters()} is false * (that is, there is "allowGetters=false" or equivalent), * otherwise returns empty {@link java.util.Set}. */ public Set findIgnoredForSerialization() { if (_allowGetters) { return Collections.emptySet(); } return _ignored; } /** * Method called to find names of properties to ignore when used for * serialization: functionally * same as {@link #getIgnored} if {@link #getAllowSetters()} is false * (that is, there is "allowSetters=false" or equivalent), * otherwise returns empty {@link java.util.Set}. */ public Set findIgnoredForDeserialization() { if (_allowSetters) { return Collections.emptySet(); } return _ignored; } public boolean getIgnoreUnknown() { return _ignoreUnknown; } public boolean getAllowGetters() { return _allowGetters; } public boolean getAllowSetters() { return _allowSetters; } public boolean getMerge() { return _merge; } @Override public String toString() { return String.format("JsonIgnoreProperties.Value(ignored=%s,ignoreUnknown=%s,allowGetters=%s,allowSetters=%s,merge=%s)", _ignored, _ignoreUnknown, _allowGetters, _allowSetters, _merge); } @Override public int hashCode() { return (_ignored.size()) + (_ignoreUnknown ? 1 : -3) + (_allowGetters ? 3 : -7) + (_allowSetters ? 7 : -11) + (_merge ? 11 : -13) ; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; return (o.getClass() == getClass()) && _equals(this, (Value) o); } private static boolean _equals(Value a, Value b) { return (a._ignoreUnknown == b._ignoreUnknown) && (a._merge == b._merge) && (a._allowGetters == b._allowGetters) && (a._allowSetters == b._allowSetters) // this last just because it can be expensive && a._ignored.equals(b._ignored) ; } private static Set _asSet(String[] v) { if (v == null || v.length == 0) { return Collections.emptySet(); } Set s = new HashSet(v.length); for (String str : v) { s.add(str); } return s; } private static Set _merge(Set s1, Set s2) { if (s1.isEmpty()) { return s2; } else if (s2.isEmpty()) { return s1; } HashSet result = new HashSet(s1.size() + s2.size()); result.addAll(s1); result.addAll(s2); return result; } private static boolean _empty(Set ignored, boolean ignoreUnknown, boolean allowGetters, boolean allowSetters, boolean merge) { if ((ignoreUnknown == EMPTY._ignoreUnknown) && (allowGetters == EMPTY._allowGetters) && (allowSetters == EMPTY._allowSetters) && (merge == EMPTY._merge)) { return (ignored == null || ignored.size() == 0); } return false; } } } JsonIgnoreType.java000066400000000000000000000021051323177441000362160ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that indicates that all properties of annotated * type are to be ignored during serialization and deserialization. *

* Note: annotation does have boolean 'value' property (which defaults * to 'true'), so that it is actually possible to override value * using mix-in annotations. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonIgnoreType { /** * Optional argument that defines whether this annotation is active * or not. The only use for value 'false' if for overriding purposes * (which is not needed often); most likely it is needed for use * with "mix-in annotations" ("annotation overrides"). * For most cases, however, default value of "true" is just fine * and should be omitted. */ boolean value() default true; } JsonInclude.java000066400000000000000000000472741323177441000355340ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to indicate when value of the annotated property (when * used for a field, method or constructor parameter), or all * properties of the annotated class, is to be serialized. * Without annotation property values are always included, but by using * this annotation one can specify simple exclusion rules to reduce * amount of properties to write out. *

* Note that the main inclusion criteria (one annotated with {@link #value}) * is checked on Java object level, for the annotated type, * and NOT on JSON output -- so even with {@link Include#NON_NULL} * it is possible that JSON null values are output, if object reference * in question is not `null`. An example is {@link java.util.concurrent.atomic.AtomicReference} * instance constructed to reference null value: such a value * would be serialized as JSON null, and not filtered out. *

* To base inclusion on value of contained value(s), you will typically also need * to specify {@link #content()} annotation; for example, specifying only * {@link #value} as {@link Include#NON_EMPTY} for a {link java.util.Map} would * exclude Maps with no values, but would include Maps * with `null` values. To exclude Map with only `null` value, you would use both * annotations like so: *

 *public class Bean {
 *   {@literal @JsonInclude}(value=Include.NON_EMPTY, content=Include.NON_NULL)
 *   public Map<String,String> entries;
 *}
 *
* Similarly you could Maps that only contain * "empty" elements, or "non-default" values (see {@link Include#NON_EMPTY} and * {@link Include#NON_DEFAULT} for more details). *

* In addition to `Map`s, `content` concept is also supported for referential * types (like {@link java.util.concurrent.atomic.AtomicReference}). * Note that `content` is NOT currently (as of Jackson 2.9) supported for * arrays or {@link java.util.Collection}s, but supported may be added in * future versions. * * @since 2.0 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonInclude { /** * Inclusion rule to use for instances (values) of types (Classes) or * properties annotated; defaults to {@link Include#ALWAYS}. */ public Include value() default Include.ALWAYS; /** * Inclusion rule to use for entries ("content") of annotated * {@link java.util.Map}s and referential types (like * {@link java.util.concurrent.atomic.AtomicReference}); * defaults to {@link Include#ALWAYS}. * * @since 2.5 */ public Include content() default Include.ALWAYS; /** * Specifies type of "Filter Object" to use in case * {@link #value} is {@link JsonInclude.Include#CUSTOM}: * if so, an instance is created by calling HandlerInstantiator * (of ObjectMapper), which by default simply calls * zero-argument constructor of the Filter Class. * * @since 2.9 */ public Class valueFilter() default Void.class; /** * Specifies type of "Filter Object" to use in case * {@link #content} is {@link JsonInclude.Include#CUSTOM}: * if so, an instance is created by calling HandlerInstantiator * (of ObjectMapper), which by default simply calls * zero-argument constructor of the Filter Class. * * @since 2.9 */ public Class contentFilter() default Void.class; /* /********************************************************** /* Value enumerations /********************************************************** */ /** * Enumeration used with {@link JsonInclude} * to define which properties * of Java Beans are to be included in serialization. */ public enum Include { /** * Value that indicates that property is to be always included, * independent of value of the property. */ ALWAYS, /** * Value that indicates that only properties with non-null * values are to be included. */ NON_NULL, /** * Value that indicates that properties are included unless their value * is: *

    *
  • null
  • *
  • "absent" value of a referential type (like Java 8 `Optional`, or * {link java.utl.concurrent.atomic.AtomicReference}); that is, something * that would not deference to a non-null value. *
* This option is mostly used to work with "Optional"s (Java 8, Guava). * * @since 2.6 */ NON_ABSENT, /** * Value that indicates that only properties with null value, * or what is considered empty, are not to be included. * Definition of emptiness is data type specific; see below * for details on actual handling. *

* Default emptiness for all types includes: *

    *
  • Null values.
  • *
  • "Absent" values (see {@link #NON_ABSENT})
  • *
* so that as baseline, "empty" set includes values that would be * excluded by both {@link #NON_NULL} and {@link #NON_ABSENT}. *
* Beyond this base, following types have additional empty values: *
    *
  • For {@link java.util.Collection}s and {@link java.util.Map}s, * method isEmpty() is called; *
  • *
  • For Java arrays, empty arrays are ones with length of 0 *
  • *
  • For Java {@link java.lang.String}s, length() is called, * and return value of 0 indicates empty String *
  • *
* and for other types, null values are excluded but other exclusions (if any). *

* Note that this default handling can be overridden by custom * JsonSerializer implementation: if method isEmpty() * is overridden, it will be called to see if non-null values are * considered empty (null is always considered empty). *

* Compatibility note: Jackson 2.6 included a wider range of "empty" values than * either earlier (up to 2.5) or later (2.7 and beyond) types; specifically: *

    *
  • Default values of primitive types (like 0 for `int`/`java.lang.Integer` * and `false` for `bool`/`Boolean`) *
  • *
  • Timestamp 0 for date/time types *
  • *
* With 2.7, definition has been tightened back to only containing types explained * above (null, absent, empty String, empty containers), and now * extended definition may be specified using {@link #NON_DEFAULT}. */ NON_EMPTY, /** * Meaning of this setting depends on context: whether annotation is * specified for POJO type (class), or not. In latter case annotation * is either used as the global default, or as property override. *

* When used for a POJO, definition is that only values that differ from * the default values of POJO properties are included. This is done * by creating an instance of POJO using zero-argument constructor, * and accessing property values: value is used as the default value * by using equals() method, except for the case where property * has `null` value in which case straight null check is used. *

* When NOT used for a POJO (that is, as a global default, or as property * override), definition is such that: *

    *
  • All values considered "empty" (as per {@link #NON_EMPTY}) are excluded
  • *
  • Primitive/wrapper default values are excluded
  • *
  • Date/time values that have timestamp (`long` value of milliseconds since * epoch, see {@link java.util.Date}) of `0L` are excluded
  • *
*/ NON_DEFAULT, /** * Value that indicates that separate `filter` Object (specified by * {@link JsonInclude#valueFilter} for value itself, and/or * {@link JsonInclude#contentFilter} for contents of structured types) * is to be used for determining inclusion criteria. * Filter object's equals() method is called with value * to serialize; if it returns true value is excluded * (that is, filtered out); if false value is included. * * @since 2.9 */ CUSTOM, /** * Pseudo-value used to indicate that the higher-level defaults make * sense, to avoid overriding inclusion value. For example, if returned * for a property this would use defaults for the class that contains * property, if any defined; and if none defined for that, then * global serialization inclusion details. * * @since 2.6 */ USE_DEFAULTS ; } /* /********************************************************** /* Value class used to enclose information /********************************************************** */ /** * Helper class used to contain information from a single {@link JsonInclude} * annotation. * * @since 2.6 */ public static class Value implements JacksonAnnotationValue, // since 2.6 java.io.Serializable { private static final long serialVersionUID = 1L; protected final static Value EMPTY = new Value(Include.USE_DEFAULTS, Include.USE_DEFAULTS, null, null); protected final Include _valueInclusion; protected final Include _contentInclusion; /** * @since 2.9 */ protected final Class _valueFilter; /** * @since 2.9 */ protected final Class _contentFilter; public Value(JsonInclude src) { this(src.value(), src.content(), src.valueFilter(), src.contentFilter()); } protected Value(Include vi, Include ci, Class valueFilter, Class contentFilter) { _valueInclusion = (vi == null) ? Include.USE_DEFAULTS : vi; _contentInclusion = (ci == null) ? Include.USE_DEFAULTS : ci; _valueFilter = (valueFilter == Void.class) ? null : valueFilter; _contentFilter = (contentFilter == Void.class) ? null : contentFilter; } public static Value empty() { return EMPTY; } /** * Helper method that will try to combine values from two {@link Value} * instances, using one as base settings, and the other as overrides * to use instead of base values when defined; base values are only * use if override does not specify a value (matching value is null * or logically missing). * Note that one or both of value instances may be `null`, directly; * if both are `null`, result will also be `null`; otherwise never null. * * @since 2.8 */ public static Value merge(Value base, Value overrides) { return (base == null) ? overrides : base.withOverrides(overrides); } /** * @since 2.8 */ public static Value mergeAll(Value... values) { Value result = null; for (Value curr : values) { if (curr != null) { result = (result == null) ? curr : result.withOverrides(curr); } } return result; } // for JDK serialization protected Object readResolve() { if ((_valueInclusion == Include.USE_DEFAULTS) && (_contentInclusion == Include.USE_DEFAULTS) && (_valueFilter == null) && (_contentFilter == null) ) { return EMPTY; } return this; } /** * Mutant factory method that merges values of this value with given override * values, so that any explicitly defined inclusion in overrides has precedence over * settings of this value instance. If no overrides exist will return this * instance; otherwise new {@link Value} with changed inclusion values. */ public Value withOverrides(Value overrides) { if ((overrides == null) || (overrides == EMPTY)) { return this; } Include vi = overrides._valueInclusion; Include ci = overrides._contentInclusion; Class vf = overrides._valueFilter; Class cf = overrides._contentFilter; boolean viDiff = (vi != _valueInclusion) && (vi != Include.USE_DEFAULTS); boolean ciDiff = (ci != _contentInclusion) && (ci != Include.USE_DEFAULTS); boolean filterDiff = (vf != _valueFilter) || (cf != _valueFilter); if (viDiff) { if (ciDiff) { return new Value(vi, ci, vf, cf); } return new Value(vi, _contentInclusion, vf, cf); } else if (ciDiff) { return new Value(_valueInclusion, ci, vf, cf); } else if (filterDiff) { return new Value(_valueInclusion, _contentInclusion, vf, cf); } return this; } /** * Factory method to use for constructing an instance for components */ public static Value construct(Include valueIncl, Include contentIncl) { if (((valueIncl == Include.USE_DEFAULTS) || (valueIncl == null)) && ((contentIncl == Include.USE_DEFAULTS) || (contentIncl == null))) { return EMPTY; } return new Value(valueIncl, contentIncl, null, null); } /** * Factory method to use for constructing an instance for components * * @since 2.9 */ public static Value construct(Include valueIncl, Include contentIncl, Class valueFilter, Class contentFilter) { if (valueFilter == Void.class) { valueFilter = null; } if (contentFilter == Void.class) { contentFilter = null; } if (((valueIncl == Include.USE_DEFAULTS) || (valueIncl == null)) && ((contentIncl == Include.USE_DEFAULTS) || (contentIncl == null)) && (valueFilter == null) && (contentFilter == null) ) { return EMPTY; } return new Value(valueIncl, contentIncl, valueFilter, contentFilter); } /** * Factory method to use for constructing an instance from instance of * {@link JsonInclude} */ public static Value from(JsonInclude src) { if (src == null) { return EMPTY; } Include vi = src.value(); Include ci = src.content(); if ((vi == Include.USE_DEFAULTS) && (ci == Include.USE_DEFAULTS)) { return EMPTY; } Class vf = src.valueFilter(); if (vf == Void.class) { vf = null; } Class cf = src.contentFilter(); if (cf == Void.class) { cf = null; } return new Value(vi, ci, vf, cf); } public Value withValueInclusion(Include incl) { return (incl == _valueInclusion) ? this : new Value(incl, _contentInclusion, _valueFilter, _contentFilter); } /** * Mutant factory that will either *
    *
  • Set value as USE_DEFAULTS * and valueFilter to filter (if filter not null); * or
  • *
  • Set value as ALWAYS (if filter null) *
  • *
* * @since 2.9 */ public Value withValueFilter(Class filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(incl, _contentInclusion, filter, _contentFilter); } /** * Mutant factory that will either *
    *
  • Set content as USE_DEFAULTS * and contentFilter to filter (if filter not null); * or
  • *
  • Set content as ALWAYS (if filter null) *
  • *
* * @since 2.9 */ public Value withContentFilter(Class filter) { Include incl; if (filter == null || filter == Void.class) { // clear filter incl = Include.USE_DEFAULTS; filter = null; } else { incl = Include.CUSTOM; } return construct(_valueInclusion, incl, _valueFilter, filter); } public Value withContentInclusion(Include incl) { return (incl == _contentInclusion) ? this : new Value(_valueInclusion, incl, _valueFilter, _contentFilter); } @Override public Class valueFor() { return JsonInclude.class; } public Include getValueInclusion() { return _valueInclusion; } public Include getContentInclusion() { return _contentInclusion; } public Class getValueFilter() { return _valueFilter; } public Class getContentFilter() { return _contentFilter; } @Override public String toString() { StringBuilder sb = new StringBuilder(80); sb.append("JsonInclude.Value(value=") .append(_valueInclusion) .append(",content=") .append(_contentInclusion); if (_valueFilter != null) { sb.append(",valueFilter=").append(_valueFilter.getName()).append(".class"); } if (_contentFilter != null) { sb.append(",contentFilter=").append(_contentFilter.getName()).append(".class"); } return sb.append(')').toString(); } @Override public int hashCode() { return (_valueInclusion.hashCode() << 2) + _contentInclusion.hashCode(); } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) return false; Value other = (Value) o; return (other._valueInclusion == _valueInclusion) && (other._contentInclusion == _contentInclusion) && (other._valueFilter == _valueFilter) && (other._contentFilter == _contentFilter) ; } } } JsonManagedReference.java000066400000000000000000000034331323177441000373110ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to indicate that annotated property is part of * two-way linkage between fields; and that its role is "parent" (or "forward") link. * Value type (class) of property must have a single compatible property annotated with * {@link JsonBackReference}. Linkage is handled such that the property * annotated with this annotation is handled normally (serialized normally, no * special handling for deserialization); it is the matching back reference * that requires special handling *

* All references have logical name to allow handling multiple linkages; typical case * would be that where nodes have both parent/child and sibling linkages. If so, * pairs of references should be named differently. * It is an error for a class too have multiple managed references with same name, * even if types pointed are different. *

* Note: only methods and fields can be annotated with this annotation: constructor * arguments should NOT be annotated, as they can not be either managed or back * references. * * @author tatu */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonManagedReference { /** * Logical have for the reference property pair; used to link managed and * back references. Default name can be used if there is just single * reference pair (for example, node class that just has parent/child linkage, * consisting of one managed reference and matching back reference) */ public String value() default "defaultReference"; } JsonMerge.java000066400000000000000000000046631323177441000352030ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation to specify whether annotated property value should use "merging" approach, * in which current value is first accessed (with a getter or field) and then modified * with incoming data, or not: if not, assignment happens without considering current state. *

* Merging is only option if there is a way to introspect current state: * if there is accessor (getter, field) to use. * Merging can not be enabled if no accessor exists * or if assignment occurs using a Creator setter (constructor * or factory method), since there is no instance with state to introspect. * Merging also only has actual effect for structured types where there is an * obvious way to update a state (for example, POJOs have default values for properties, * and {@link java.util.Collection}s and {@link java.util.Map}s may have existing * elements; whereas scalar types do not such state: an int has a value, * but no obvious and non-ambiguous way to merge state. *

* Merging is applied by using a deserialization method that accepts existing state * as an argument: it is then up to JsonDeserializer implementation * to use that base state in a way that makes sense without further configuration. * For structured types this is usually obvious; and for scalar types not -- if * no obvious method exists, merging is not allowed; deserializer may choose to * either quietly ignore it, or throw an exception. *

* Note that use of merging usually adds some processing overhead since it adds * an extra step of accessing the current state before assignment. *

* Note also that "root values" (values directly deserialized and not reached * via POJO properties) can not use this annotation; instead, ObjectMapper * and Object have "updating reader" operations. *

* Default value is {@link OptBoolean#TRUE}, that is, merging is enabled. * * @since 2.9 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonMerge { /** * Whether merging should or should not be enabled for the annotated property. */ OptBoolean value() default OptBoolean.TRUE; } JsonProperty.java000066400000000000000000000150251323177441000357620ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that can be used to define a non-static * method as a "setter" or "getter" for a logical property * (depending on its signature), * or non-static object field to be used (serialized, deserialized) as * a logical property. *

* Default value ("") indicates that the field name is used * as the property name without any modifications, but it * can be specified to non-empty value to specify different * name. Property name refers to name used externally, as * the field name in JSON objects. *

* Starting with Jackson 2.6 this annotation may also be * used to change serialization of Enum like so: *

public enum MyEnum {
    {@literal @JsonProperty}("theFirstValue") THE_FIRST_VALUE,
    {@literal @JsonProperty}("another_value") ANOTHER_VALUE;
}
* as an alternative to using {@link JsonValue} annotation. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonProperty { /** * Special value that indicates that handlers should use the default * name (derived from method or field name) for property. * * @since 2.1 */ public final static String USE_DEFAULT_NAME = ""; /** * Marker value used to indicate that no index has been specified. * Used as the default value as annotations do not allow "missing" * values. * * @since 2.4 */ public final static int INDEX_UNKNOWN = -1; /** * Defines name of the logical property, i.e. JSON object field * name to use for the property. If value is empty String (which is the * default), will try to use name of the field that is annotated. * Note that there is * no default name available for constructor arguments, * meaning that * Empty String is not a valid value for constructor arguments. */ String value() default USE_DEFAULT_NAME; /** * Property that indicates whether a value (which may be explicit * null) is expected for property during deserialization or not. * If expected, BeanDeserialized should indicate * this as a validity problem (usually by throwing an exception, * but this may be sent via problem handlers that can try to * rectify the problem, for example, by supplying a default * value). *

* Note that as of 2.6, this property is only used for Creator * Properties, to ensure existence of property value in JSON: * for other properties (ones injected using a setter or mutable * field), no validation is performed. Support for those cases * may be added in future. * State of this property is exposed via introspection, and its * value is typically used by Schema generators, such as one for * JSON Schema. * * @since 2.0 */ boolean required() default false; /** * Property that indicates numerical index of this property (relative * to other properties specified for the Object). This index * is typically used by binary formats, but may also be useful * for schema languages and other tools. * * @since 2.4 */ int index() default INDEX_UNKNOWN; /** * Property that may be used to document expected default value * for the property: most often used as source information for generating * schemas (like JSON Schema or protobuf/thrift schema), or documentation. * It may also be used by Jackson extension modules; core jackson databind * does not have any automated handling beyond simply exposing this * value through bean property introspection. *

* It is possible that in future this annotation could be used for value * defaulting, and especially for default values of Creator properties, * since they support {@link #required()} in 2.6 and above. * * @since 2.5 */ String defaultValue() default ""; /** * Optional property that may be used to change the way visibility of * accessors (getter, field-as-getter) and mutators (contructor parameter, * setter, field-as-setter) is determined, either so that otherwise * non-visible accessors (like private getters) may be used; or that * otherwise visible accessors are ignored. *

* Default value os {@link Access#AUTO} which means that access is determined * solely based on visibility and other annotations. * * @since 2.6 */ Access access() default Access.AUTO; /** * Various options for {@link #access} property, specifying how property * may be accessed during serialization ("read") and deserialization ("write") * (note that the direction of read and write is from perspective of the property, * not from external data format: this may be confusing in some contexts). *

* Note that while this annotation modifies access to annotated property, * its effects may be further overridden by {@link JsonIgnore} property: * if both annotations are present on an accessors, {@link JsonIgnore} * has precedence over this property. * This annotation property is, however, preferred over use of "split" * {@link JsonIgnore}/JsonProperty combination. * * @since 2.6 */ public enum Access { /** * Access setting which means that visibility rules are to be used * to automatically determine read- and/or write-access of this property. */ AUTO, /** * Access setting that means that the property may only be read for serialization, * but not written (set) during deserialization. */ READ_ONLY, /** * Access setting that means that the property may only be written (set) * for deserialization, * but will not be read (get) on serialization, that is, the value of the property * is not included in serialization. */ WRITE_ONLY, /** * Access setting that means that the property will be accessed for both * serialization (writing out values as external representation) * and deserialization (reading values from external representation), * regardless of visibility rules. */ READ_WRITE ; } } JsonPropertyDescription.java000066400000000000000000000015461323177441000401710ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to define a human readable description for a logical * property. * Currently used to populate the description field in generated JSON * Schemas. * * @since 2.3 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented // since 2.6 @JacksonAnnotation public @interface JsonPropertyDescription { /** * Defines a human readable description of the logical property. * Currently used to populate the description field in generated JSON * Schemas. */ String value() default ""; } JsonPropertyOrder.java000066400000000000000000000036071323177441000367610ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation that can be used to define ordering (possibly partial) to use * when serializing object properties. Properties included in annotation * declaration will be serialized first (in defined order), followed by * any properties not included in the definition. * Annotation definition will override any implicit orderings (such as * guarantee that Creator-properties are serialized before non-creator * properties) *

* Examples: *

 *  // ensure that "id" and "name" are output before other properties
 *  @JsonPropertyOrder({ "id", "name" })
 *  // order any properties that don't have explicit setting using alphabetic order
 *  @JsonPropertyOrder(alphabetic=true)
 *
*

* This annotation may or may not have effect on deserialization: for basic JSON * handling there is no effect, but for other supported data types (or structural * conventions) there may be. *

* NOTE: annotation is allowed for properties, starting with 2.4, mostly to support * alphabetic ordering of {@link java.util.Map} entries. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonPropertyOrder { /** * Order in which properties of annotated object are to be serialized in. */ public String[] value() default { }; /** * Property that defines what to do regarding ordering of properties * not explicitly included in annotation instance. If set to true, * they will be alphabetically ordered; if false, order is * undefined (default setting) */ public boolean alphabetic() default false; } JsonRawValue.java000066400000000000000000000023251323177441000356630ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that indicates that the annotated method * or field should be serialized by including literal String value * of the property as is, without quoting of characters. * This can be useful for injecting values already serialized in JSON or * passing javascript function definitions from server to a javascript client. *

* Warning: the resulting JSON stream may be invalid depending on your input value. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD }) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonRawValue { /** * Optional argument that defines whether this annotation is active * or not. The only use for value 'false' if for overriding purposes * (which is not needed often); most likely it is needed for use * with "mix-in annotations" (aka "annotation overrides"). * For most cases, however, default value of "true" is just fine * and should be omitted. */ boolean value() default true; } JsonRootName.java000066400000000000000000000032011323177441000356530ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation similar to {@link javax.xml.bind.annotation.XmlRootElement}, * used to indicate name to use for root-level wrapping, if wrapping is * enabled. Annotation itself does not indicate that wrapping should * be used; but if it is, name used for serialization should be name * specified here, and deserializer will expect the name as well. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @com.fasterxml.jackson.annotation.JacksonAnnotation public @interface JsonRootName { /** * Root name to use if root-level wrapping is enabled. For data formats * that use composite names (XML), this is the "local part" of the name * to use. */ public String value(); /** * Optional namespace to use with data formats that support such * concept (specifically XML); if so, used with {@link #value} to * construct fully-qualified name. * * @since 2.4 */ public String namespace() default ""; /* * Optional marker property that can be defined as true to force * wrapping of root element, regardless of whether globally * "root wrapping" is enabled or not. *

* Note that value of false is taken to mean "use defaults", * and will not block use of wrapper if use is indicated by global features. * * @since 2.4 public boolean alwaysWrap() default false; */ } JsonSetter.java000066400000000000000000000227501323177441000354070ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.*; /** * Annotation that can be used to define a non-static, * single-argument method to be used as a "setter" for a logical property * as an alternative to recommended * {@link JsonProperty} annotation; * or (as of 2.9 and later), specify additional aspects of the * assigning property a value during serialization. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) // ^^^ allowed on Fields, (constructor) parameters since 2.9 @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonSetter { /** * Optional default argument that defines logical property this * method is used to modify ("set"); this is the property * name used in JSON content. */ String value() default ""; /** * Specifies action to take when input contains explicit `null` value * (if format has one). * Default action, in absence of any explicit configuration, * is usually {@link Nulls#SET}, meaning that the `null` is set as * value using setter. *

* NOTE: is not usually used in case property value is missing, unless * data format specifies that there is defaulting which would result * in an explicit null assignment. */ Nulls nulls() default Nulls.DEFAULT; /** * Specifies action to take when input to match into content value * (of a {@link java.util.Collection}, {@link java.util.Map}, array, * or referential value) contains explicit `null` value * (if format has one) to bind. * Default action, in absence of any explicit configuration, * is usually {@link Nulls#SET}, meaning that the `null` is included as usual. */ Nulls contentNulls() default Nulls.DEFAULT; /* /********************************************************** /* Value class used to enclose information, allow for /* merging of layered configuration settings. /********************************************************** */ /** * Helper class used to contain information from a single {@link JsonSetter} * annotation, as well as to provide possible overrides from non-annotation sources. * * @since 2.9 */ public static class Value implements JacksonAnnotationValue, java.io.Serializable { private static final long serialVersionUID = 1L; private final Nulls _nulls; private final Nulls _contentNulls; /** * Default instance used in place of "default settings". */ protected final static Value EMPTY = new Value(Nulls.DEFAULT, Nulls.DEFAULT); protected Value(Nulls nulls, Nulls contentNulls) { _nulls = nulls; _contentNulls = contentNulls; } @Override public Class valueFor() { return JsonSetter.class; } // for JDK serialization protected Object readResolve() { if (_empty(_nulls, _contentNulls)) { return EMPTY; } return this; } public static Value from(JsonSetter src) { if (src == null) { return EMPTY; } return construct(src.nulls(), src.contentNulls()); } /** * Factory method that may be used (although is NOT the recommended way) * to construct an instance from a full set of properties. Most users would * be better of starting by {@link #empty()} instance and using `withXxx`/`withoutXxx` * methods, as this factory method may need to be changed if new properties * are added in {@link JsonIgnoreProperties} annotation. */ public static Value construct(Nulls nulls, Nulls contentNulls) { if (nulls == null) { nulls = Nulls.DEFAULT; } if (contentNulls == null) { contentNulls = Nulls.DEFAULT; } if (_empty(nulls, contentNulls)) { return EMPTY; } return new Value(nulls, contentNulls); } /** * Accessor for default instances which has "empty" settings; that is: *

    *
  • Null handling using global defaults, {@link Nulls#DEFAULT}. *
  • *
*/ public static Value empty() { return EMPTY; } /** * Helper method that will try to combine values from two {@link Value} * instances, using one as base settings, and the other as overrides * to use instead of base values when defined; base values are only * use if override does not specify a value (matching value is null * or logically missing). * Note that one or both of value instances may be `null`, directly; * if both are `null`, result will also be `null`; otherwise never null. */ public static Value merge(Value base, Value overrides) { return (base == null) ? overrides : base.withOverrides(overrides); } public static Value forValueNulls(Nulls nulls) { return construct(nulls, Nulls.DEFAULT); } public static Value forValueNulls(Nulls nulls, Nulls contentNulls) { return construct(nulls, contentNulls); } public static Value forContentNulls(Nulls nulls) { return construct(Nulls.DEFAULT, nulls); } /** * Mutant factory method that merges values of this value with given override * values, so that any explicitly defined inclusion in overrides has precedence over * settings of this value instance. If no overrides exist will return this * instance; otherwise new {@link Value} with changed inclusion values. */ public Value withOverrides(Value overrides) { if ((overrides == null) || (overrides == EMPTY)) { return this; } Nulls nulls = overrides._nulls; Nulls contentNulls = overrides._contentNulls; if (nulls == Nulls.DEFAULT) { nulls = _nulls; } if (contentNulls == Nulls.DEFAULT) { contentNulls = _contentNulls; } if ((nulls == _nulls) && (contentNulls == _contentNulls)) { return this; } return construct(nulls, contentNulls); } public Value withValueNulls(Nulls nulls) { if (nulls == null) { nulls = Nulls.DEFAULT; } if (nulls == _nulls) { return this; } return construct(nulls, _contentNulls); } public Value withValueNulls(Nulls valueNulls, Nulls contentNulls) { if (valueNulls == null) { valueNulls = Nulls.DEFAULT; } if (contentNulls == null) { contentNulls = Nulls.DEFAULT; } if ((valueNulls == _nulls) && (contentNulls == _contentNulls)) { return this; } return construct(valueNulls, contentNulls); } public Value withContentNulls(Nulls nulls) { if (nulls == null) { nulls = Nulls.DEFAULT; } if (nulls == _contentNulls) { return this; } return construct(_nulls, nulls); } public Nulls getValueNulls() { return _nulls; } public Nulls getContentNulls() { return _contentNulls; } /** * Returns same as {@link #getValueNulls()} unless value would be * {@link Nulls#DEFAULT} in which case `null` is returned. */ public Nulls nonDefaultValueNulls() { return (_nulls == Nulls.DEFAULT) ? null : _nulls; } /** * Returns same as {@link #getContentNulls()} unless value would be * {@link Nulls#DEFAULT} in which case `null` is returned. */ public Nulls nonDefaultContentNulls() { return (_contentNulls == Nulls.DEFAULT) ? null : _contentNulls; } /* /********************************************************** /* Std method overrides /********************************************************** */ @Override public String toString() { return String.format("JsonSetter.Value(valueNulls=%s,contentNulls=%s)", _nulls, _contentNulls); } @Override public int hashCode() { return _nulls.ordinal() + (_contentNulls.ordinal() << 2); } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() == getClass()) { Value other = (Value) o; return (other._nulls == _nulls) && (other._contentNulls == _contentNulls); } return false; } /* /********************************************************** /* Internal methods /********************************************************** */ private static boolean _empty(Nulls nulls, Nulls contentNulls) { return (nulls == Nulls.DEFAULT) && (contentNulls == Nulls.DEFAULT); } } } JsonSubTypes.java000066400000000000000000000034371323177441000357200ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used with {@link JsonTypeInfo} to indicate sub-types of serializable * polymorphic types, and to associate logical names used within JSON content * (which is more portable than using physical Java class names). *

* Note that just annotating a property or base type with this annotation does * NOT enable polymorphic type handling: in addition, {@link JsonTypeInfo} * or equivalent (such as enabling of so-called "default typing") annotation * is needed, and only in such case is subtype information used. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonSubTypes { /** * Subtypes of the annotated type (annotated class, or property value type * associated with the annotated method). These will be checked recursively * so that types can be defined by only including direct subtypes. */ public Type[] value(); /** * Definition of a subtype, along with optional name. If name is missing, class * of the type will be checked for {@link JsonTypeName} annotation; and if that * is also missing or empty, a default * name will be constructed by type id mechanism. * Default name is usually based on class name. */ public @interface Type { /** * Class of the subtype */ public Class value(); /** * Logical type name used as the type identifier for the class */ public String name() default ""; } } JsonTypeId.java000066400000000000000000000027201323177441000353320ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation that can be used on a property accessor * (field, getter or setter, constructor parameter) to indicate that * the property is to contain type id to use when including * polymorphic type information. * Annotation should only be used if the intent is to override * generation of standard type id: if so, value of the property will be * accessed during serialization and used as the type id. *

* On deserialization annotation has no effect, as visibility of type id * is governed by value of {@link JsonTypeInfo#visible}; properties with * this annotation get no special handling. *

* On serialization, this annotation will exclude property from being * serialized along other properties; instead, its value is serialized * as the type identifier. Since type identifier may be included in * various places, it may still appear like 'normal' property (when using * {@link JsonTypeInfo.As#PROPERTY}), but is more commonly embedded * in a different place, as per inclusion rules (see {@link JsonTypeInfo} * for details). * * @since 2.0 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonTypeId { } JsonTypeInfo.java000066400000000000000000000325561323177441000357030ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.*; /** * Annotation used for configuring details of if and how type information is * used with JSON serialization and deserialization, to preserve information * about actual class of Object instances. This is necessarily for polymorphic * types, and may also be needed to link abstract declared types and matching * concrete implementation. *

* Some examples of typical annotations: *

 *  // Include Java class name ("com.myempl.ImplClass") as JSON property "class"
 *  @JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="class")
 *  
 *  // Include logical type name (defined in impl classes) as wrapper; 2 annotations
 *  @JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
 *  @JsonSubTypes({com.myemp.Impl1.class, com.myempl.Impl2.class})
 *
* Alternatively you can also define fully customized type handling by using * @JsonTypeResolver annotation (from databind package). *

* This annotation can be used both for types (classes) and properties. * If both exist, annotation on property has precedence, as it is * considered more specific. *

* When used for properties (fields, methods), this annotation applies * to values: so when applied to structure types * (like {@link java.util.Collection}, {@link java.util.Map}, arrays), * will apply to contained values, not the container; * for non-structured types there is no difference. * This is identical to how JAXB handles type information * annotations; and is chosen since it is the dominant use case. * There is no per-property way to force type information to be included * for type of container (structured type); for container types one has * to use annotation for type declaration. *

* Note on visibility of type identifier: by default, deserialization * (use during reading of JSON) of type identifier * is completely handled by Jackson, and is not passed to * deserializers. However, if so desired, * it is possible to define property visible = true * in which case property will be passed as-is to deserializers * (and set via setter or field) on deserialization. *

* On serialization side, Jackson will generate type id by itself, * except if there is a property with name that matches * {@link #property()}, in which case value of that property is * used instead. *

* NOTE: use of type id of "class name" with very general base type * (such as {@link java.lang.Object} or {@link java.io.Serializable}) * can potentially open up security holes if deserializing content * generated by untrusted sources. If content can not be trusted, * it is necessary to either use "type name" as type id, or to * limit possible types using other means. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonTypeInfo { /* /********************************************************** /* Value enumerations used for properties /********************************************************** */ /** * Definition of different type identifiers that can be included in JSON * during serialization, and used for deserialization. */ public enum Id { /** * This means that no explicit type metadata is included, and typing is * purely done using contextual information possibly augmented with other * annotations. */ NONE(null), /** * Means that fully-qualified Java class name is used as the type identifier. */ CLASS("@class"), /** * Means that Java class name with minimal path is used as the type identifier. * Minimal means that only the class name, and that part of preceding Java * package name is included that is needed to construct fully-qualified name * given fully-qualified name of the declared supertype; additionally a single * leading dot ('.') must be used to indicate that partial class name is used. * For example, for supertype "com.foobar.Base", and concrete type * "com.foo.Impl", only ".Impl" would be included; and for "com.foo.impl.Impl2" * only ".impl.Impl2" would be included. *
* NOTE: leading dot ('.') MUST be used to denote partial (minimal) name; * if it is missing, value is assumed to be fully-qualified name. Fully-qualified * name is used in cases where subtypes are not in same package (or sub-package * thereof) as base class. *

* If all related classes are in the same Java package, this option can reduce * amount of type information overhead, especially for small types. * However, please note that using this alternative is inherently risky since it * assumes that the * supertype can be reliably detected. Given that it is based on declared type * (since ultimate supertype, java.lang.Object would not be very * useful reference point), this may not always work as expected. */ MINIMAL_CLASS("@c"), /** * Means that logical type name is used as type information; name will then need * to be separately resolved to actual concrete type (Class). */ NAME("@type"), /** * Means that typing mechanism uses customized handling, with possibly * custom configuration. This means that semantics of other properties is * not defined by Jackson package, but by the custom implementation. */ CUSTOM(null) ; private final String _defaultPropertyName; private Id(String defProp) { _defaultPropertyName = defProp; } public String getDefaultPropertyName() { return _defaultPropertyName; } } /** * Definition of standard type inclusion mechanisms for type metadata. * Used for standard metadata types, except for {@link Id#NONE}. * May or may not be used for custom types ({@link Id#CUSTOM}). */ public enum As { /** * Inclusion mechanism that uses a single configurable property, included * along with actual data (POJO properties) as a separate meta-property. *

* Default choice for inclusion. */ PROPERTY, /** * Inclusion mechanism that wraps typed JSON value (POJO * serialized as JSON) in * a JSON Object that has a single entry, * where field name is serialized type identifier, * and value is the actual JSON value. *

* Note: can only be used if type information can be serialized as * String. This is true for standard type metadata types, but not * necessarily for custom types. */ WRAPPER_OBJECT, /** * Inclusion mechanism that wraps typed JSON value (POJO * serialized as JSON) in * a 2-element JSON array: first element is the serialized * type identifier, and second element the serialized POJO * as JSON Object. */ WRAPPER_ARRAY, /** * Inclusion mechanism similar to PROPERTY, except that * property is included one-level higher in hierarchy, i.e. as sibling * property at same level as JSON Object to type. * Note that this choice can only be used for properties, not * for types (classes). Trying to use it for classes will result in * inclusion strategy of basic PROPERTY instead. */ EXTERNAL_PROPERTY, /** * Inclusion mechanism similar to PROPERTY with respect * to deserialization; but one that is produced by a "regular" accessible * property during serialization. This means that TypeSerializer * will do nothing, and expects a property with defined name to be output * using some other mechanism (like default POJO property serialization, or * custom serializer). *

* Note that this behavior is quite similar to that of using {@link JsonTypeId} * annotation; * except that here TypeSerializer is basically suppressed; * whereas with {@link JsonTypeId}, output of regular property is suppressed. * This mostly matters with respect to output order; this choice is the only * way to ensure specific placement of type id during serialization. * * @since 2.3.0 but databind only since 2.5.0. */ EXISTING_PROPERTY ; } /* /********************************************************** /* Annotation properties /********************************************************** */ /** * Specifies kind of type metadata to use when serializing * type information for instances of annotated type * and its subtypes; as well as what is expected during * deserialization. */ public Id use(); /** * Specifies mechanism to use for including type metadata (if any; for * {@link Id#NONE} nothing is included); used when serializing, * and expected when deserializing. *

* Note that for type metadata type of {@link Id#CUSTOM}, * this setting may or may not have any effect. */ public As include() default As.PROPERTY; /** * Property names used when type inclusion method ({@link As#PROPERTY}) is used * (or possibly when using type metadata of type {@link Id#CUSTOM}). * If POJO itself has a property with same name, value of property * will be set with type id metadata: if no such property exists, type id * is only used for determining actual type. *

* Default property name used if this property is not explicitly defined * (or is set to empty String) is based on * type metadata type ({@link #use}) used. */ public String property() default ""; /** * Optional property that can be used to specify default implementation * class to use for deserialization if type identifier is either not present, * or can not be mapped to a registered type (which can occur for ids, * but not when specifying explicit class to use). * Property has no effect on choice of type id used for serialization; * it is only used in deciding what to do for otherwise unmappable cases. *

* Note that while this property allows specification of the default * implementation to use, it does not help with structural issues that * may arise if type information is missing. This means that most often * this is used with type-name -based resolution, to cover cases * where new sub-types are added, but base type is not changed to * reference new sub-types. *

* There are certain special values that indicate alternate behavior: *

    *
  • {@link java.lang.Void} means that objects with unmappable (or missing) * type are to be mapped to null references. * For backwards compatibility (2.5 and below), value of * com.fasterxml.jackson.databind.annotation.NoClass is also allowed * for such usage. *
  • *
  • Placeholder value of {@link JsonTypeInfo} (that is, this annotation type * itself} means "there is no default implementation" (in which * case an error results from unmappable type). * For backwards compatibility with earlier versions (2.5 and below), * value of {@link JsonTypeInfo.None} may also be used. *
  • *
*/ public Class defaultImpl() default JsonTypeInfo.class; /** * Property that defines whether type identifier value will be passed * as part of JSON stream to deserializer (true), or handled and * removed by TypeDeserializer (false). * Property has no effect on serialization. *

* Default value is false, meaning that Jackson handles and removes * the type identifier from JSON content that is passed to * JsonDeserializer. * * @since 2.0 */ public boolean visible() default false; // 19-Dec-2014, tatu: Was hoping to implement for 2.5, but didn't quite make it. // Hope for better luck with 2.8 or later /** * Property that defines whether type serializer is allowed to omit writing * of type id, in case that value written has type same as {@link #defaultImpl()}. * If true, omission is allowed (although writer may or may not be able to do that); * if false, type id should always be written still. * * @since 2.5 public boolean skipWritingDefault() default false; /* /* /********************************************************** /* Helper classes /********************************************************** */ /** * This marker class that is only to be used with defaultImpl * annotation property, to indicate that there is no default implementation * specified. * * @deprecated Since 2.5, use any Annotation type (such as {@link JsonTypeInfo}, * if such behavior is needed; this is rarely necessary. */ @Deprecated public abstract static class None { } } JsonTypeName.java000066400000000000000000000014531323177441000356600ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used for binding logical name that the annotated class * has. Used with {@link JsonTypeInfo} (and specifically its * {@link JsonTypeInfo#use} property) to establish relationship * between type names and types. * * @author tatu */ @Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonTypeName { /** * Logical type name for annotated type. If missing (or defined as Empty String), * defaults to using non-qualified class name as the type. */ public String value() default ""; } JsonUnwrapped.java000066400000000000000000000050731323177441000361050ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used to indicate that a property should be serialized * "unwrapped"; that is, if it would be serialized as JSON Object, its * properties are instead included as properties of its containing * Object. For example, consider case of POJO like: * *

 *  public class Parent {
 *    public int age;
 *    public Name name;
 *  }
 *  public class Name {
 *    public String first, last;
 *  }
 *
* which would normally be serialized as follows (assuming @JsonUnwrapped * had no effect): *
 *  {
 *    "age" : 18,
 *    "name" : {
 *      "first" : "Joey",
 *      "last" : "Sixpack"
 *    }
 *  }
 *
* can be changed to this: *
 *  {
 *    "age" : 18,
 *    "first" : "Joey",
 *    "last" : "Sixpack"
 *  }
 *
* by changing Parent class to: *
 *  public class Parent {
 *    public int age;
 *    @JsonUnwrapped
 *    public Name name;
 *  }
 *
* Annotation can only be added to properties, and not classes, as it is contextual. *

* Also note that annotation only applies if *

    *
  • Value is serialized as JSON Object (can not unwrap JSON arrays using this * mechanism) *
  • *
  • Serialization is done using BeanSerializer, not a custom serializer *
  • *
  • No type information is added; if type information needs to be added, structure can * not be altered regardless of inclusion strategy; so annotation is basically ignored. *
  • *
*/ @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonUnwrapped { /** * Property that is usually only used when overriding (masking) annotations, * using mix-in annotations. Otherwise default value of 'true' is fine, and * value need not be explicitly included. */ boolean enabled() default true; /** * Optional property that can be used to add prefix String to use in front * of names of properties that are unwrapped: this can be done for example to prevent * name collisions. */ String prefix() default ""; /** * Optional property that can be used to add suffix String to append at the end * of names of properties that are unwrapped: this can be done for example to prevent * name collisions. */ String suffix() default ""; } JsonValue.java000066400000000000000000000047241323177441000352160ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Marker annotation * that indicates that the value of annotated accessor (either field * or "getter" method [a method with non-void return type, no args]) * is to be used as the single value to serialize for the instance, * instead of the usual method of collecting properties of value. * Usually value will be of a simple scalar type * (String or Number), but it can be any serializable type (Collection, * Map or Bean). *

* At most one accessor of a Class can be annotated with this annotation; * if more than one is found, an exception may be thrown. * Also, if method signature of annotated method is not compatible with Getters, * an exception may be thrown (whether exception is thrown or not is an * implementation detail (due to filtering during introspection, some annotations * may be skipped) and applications should not rely on specific behavior). *

* A typical usage is that of annotating toString() * method so that returned String value is used as the JSON serialization; * and if deserialization is needed, there is matching constructor * or factory method annotated with {@link JsonCreator} annotation. *

* Boolean argument is only used so that sub-classes can "disable" * annotation if necessary. *

* NOTE: when use for Java enums, one additional feature is * that value returned by annotated method is also considered to be the * value to deserialize from, not just JSON String to serialize as. * This is possible since set of Enum values is constant and it is possible * to define mapping, but can not be done in general for POJO types; as such, * this is not used for POJO deserialization. * * @see JsonCreator */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD // since 2.9 }) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonValue { /** * Optional argument that defines whether this annotation is active * or not. The only use for value 'false' if for overriding purposes. * Overriding may be necessary when used * with "mix-in annotations" (aka "annotation overrides"). * For most cases, however, default value of "true" is just fine * and should be omitted. */ boolean value() default true; } JsonView.java000066400000000000000000000027641323177441000350560ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import com.fasterxml.jackson.annotation.JacksonAnnotation; /** * Annotation used for indicating view(s) that the property * that is defined by method or field annotated is part of. *

* An example annotation would be: *

 *  @JsonView(BasicView.class)
 *
* which would specify that property annotated would be included * when processing (serializing, deserializing) View identified * by BasicView.class (or its sub-class). * If multiple View class identifiers are included, property will * be part of all of them. *

* Starting with 2.9, it is also possible to use this annotation on * POJO classes to indicate the default view(s) for properties of the * type, unless overridden by per-property annotation. */ @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, // since 2.5 ElementType.TYPE // since 2.9, to indicate "default view" for properties }) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation public @interface JsonView { /** * View or views that annotated element is part of. Views are identified * by classes, and use expected class inheritance relationship: child * views contain all elements parent views have, for example. */ public Class[] value() default { }; } Nulls.java000066400000000000000000000024611323177441000344010ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; /** * Enumeration used with {@link JsonSetter} (for properties `nulls` * and `contentNulls`) * to define how explicit `null` values from input (if input format * has the concept; JSON, for example does) are handled. */ public enum Nulls { /** * Value that indicates that an input null should result in assignment * of Java `null` value of matching property (except where deserializer * indicates other "null value" by overriding getNullValue(...) * method) */ SET, /** * Value that indicates that an input null value should be skipped and * no assignment is to be made; this usually means that the property * will have its default value. */ SKIP, /** * Value that indicates that an exception (of type that indicates input mismatch * problem) is to be thrown, to indicate that null values are not accepted. */ FAIL, /** * Value that indicates that value to assign should come from the value * deserializer of the type, using method getEmptyValue(). */ AS_EMPTY, /** * Pseudo-value used to indicate that defaults are to be used for handling, * that is, this value specifies no explicit handling override. */ DEFAULT ; }ObjectIdGenerator.java000066400000000000000000000141121323177441000366320ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; /** * Definition of API used for constructing Object Identifiers * (as annotated using {@link JsonIdentityInfo}). * Also defines factory methods used for creating instances * for serialization, deserialization. * * @param Type of Object Identifiers produced. */ @SuppressWarnings("serial") public abstract class ObjectIdGenerator implements java.io.Serializable { /* /********************************************************** /* Accessors /********************************************************** */ public abstract Class getScope(); /** * Method called to check whether this generator instance can * be used for Object Ids of specific generator type and * scope; determination is based by passing a configured * "blueprint" (prototype) instance; from which the actual * instances are created (using {@link #newForSerialization}). * * @return True if this instance can be used as-is; false if not */ public abstract boolean canUseFor(ObjectIdGenerator gen); /** * Accessor that needs to be overridden to return true * if the Object Id may be serialized as JSON Object; used by, for example, * JSOG handling. * The reason accessor is needed is because handling such Object Ids is * more complex and may incur additional buffering or performance overhead, * avoiding of which makes sense for common case of scalar object ids * (or native object ids some formats support). *

* Default implementation returns false, so needs to be overridden * by Object-producing generators. * * @since 2.5 */ public boolean maySerializeAsObject() { return false; } /** * Accessor that may be called (after verifying (via {@link #maySerializeAsObject()}) * whether given name * * @param name Name of property to check * @param parser Parser that points to property name, in case generator needs * further verification (note: untyped, because JsonParser is defined * in `jackson-core`, and this package does not depend on it). * * @since 2.5 */ public boolean isValidReferencePropertyName(String name, Object parser) { return false; } /* /********************************************************** /* Factory methods /********************************************************** */ /** * Factory method to create a blueprint instance for specified * scope. Generators that do not use scope may return 'this'. */ public abstract ObjectIdGenerator forScope(Class scope); /** * Factory method called to create a new instance to use for * serialization: needed since generators may have state * (next id to produce). *

* Note that actual type of 'context' is * com.fasterxml.jackson.databind.SerializerProvider, * but can not be declared here as type itself (as well as call * to this object) comes from databind package. * * @param context Serialization context object used (of type * com.fasterxml.jackson.databind.SerializerProvider; * may be needed by more complex generators to access contextual * information such as configuration. */ public abstract ObjectIdGenerator newForSerialization(Object context); /** * Method for constructing key to use for ObjectId-to-POJO maps. */ public abstract IdKey key(Object key); /* /********************************************************** /* Methods for serialization /********************************************************** */ /** * Method used for generating a new Object Identifier to serialize * for given POJO. * * @param forPojo POJO for which identifier is needed * * @return Object Identifier to use. */ public abstract T generateId(Object forPojo); /* /********************************************************** /* Helper classes /********************************************************** */ /** * Simple key class that can be used as a key for * ObjectId-to-POJO mappings, when multiple ObjectId types * and scopes are used. */ public final static class IdKey implements java.io.Serializable { private static final long serialVersionUID = 1L; /** * Type of {@link ObjectIdGenerator} used for generating Object Id */ public final Class type; /** * Scope of the Object Id (may be null, to denote global) */ public final Class scope; /** * Object for which Object Id was generated: can NOT be null. */ public final Object key; private final int hashCode; public IdKey(Class type, Class scope, Object key) { if (key == null) { throw new IllegalArgumentException("Can not construct IdKey for null key"); } this.type = type; this.scope = scope; this.key = key; int h = key.hashCode() + type.getName().hashCode(); if (scope != null) { h ^= scope.getName().hashCode(); } hashCode = h; } @Override public int hashCode() { return hashCode; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) return false; IdKey other = (IdKey) o; return (other.key.equals(key)) && (other.type == type) && (other.scope == scope); } @Override public String toString() { return String.format("[ObjectId: key=%s, type=%s, scope=%s]", key, (type == null) ? "NONE" : type.getName(), (scope == null) ? "NONE" : scope.getName()); } } } ObjectIdGenerators.java000066400000000000000000000170651323177441000370270ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.util.UUID; /** * Container class for standard {@link ObjectIdGenerator} implementations: *

    *
  • {@link IntSequenceGenerator} *
  • {@link PropertyGenerator} *
  • {@link StringIdGenerator} (since 2.7) *
  • {@link UUIDGenerator} *
*

* NOTE: {@link PropertyGenerator} applicability is limited in one case: it can only * be used on polymorphic base types (ones indicated using {@link JsonTypeInfo} or * default typing) via class annotations: property annotation will fail due to lack * of access to property, needed to determine type of Object Id for deserialization. * This limitation may be lifted in future versions but it is the limitation at least * up to and including Jackson 2.9. */ public class ObjectIdGenerators { /** * Shared base class for concrete implementations. */ @SuppressWarnings("serial") private abstract static class Base extends ObjectIdGenerator { protected final Class _scope; protected Base(Class scope) { _scope = scope; } @Override public final Class getScope() { return _scope; } @Override public boolean canUseFor(ObjectIdGenerator gen) { return (gen.getClass() == getClass()) && (gen.getScope() == _scope); } @Override public abstract T generateId(Object forPojo); } /* /********************************************************** /* Implementation classes /********************************************************** */ /** * Abstract marker class used to allow explicitly specifying * that no generator is used; which also implies that no * Object Id is to be included or used. */ @SuppressWarnings("serial") public abstract static class None extends ObjectIdGenerator { } /** * Abstract place-holder class which is used to denote case * where Object Identifier to use comes from a POJO property * (getter method or field). If so, value is written directly * during serialization, and used as-is during deserialization. *

* Actual implementation class is part of databind * package. */ public abstract static class PropertyGenerator extends Base { private static final long serialVersionUID = 1L; protected PropertyGenerator(Class scope) { super(scope); } } /** * Simple sequence-number based generator, which uses basic Java * ints (starting with value 1) as Object Identifiers. */ public final static class IntSequenceGenerator extends Base { private static final long serialVersionUID = 1L; protected transient int _nextValue; public IntSequenceGenerator() { this(Object.class, -1); } public IntSequenceGenerator(Class scope, int fv) { super(scope); _nextValue = fv; } protected int initialValue() { return 1; } @Override public ObjectIdGenerator forScope(Class scope) { return (_scope == scope) ? this : new IntSequenceGenerator(scope, _nextValue); } @Override public ObjectIdGenerator newForSerialization(Object context) { return new IntSequenceGenerator(_scope, initialValue()); } @Override public IdKey key(Object key) { // 02-Apr-2015, tatu: As per [annotations#56], should check for null if (key == null) { return null; } return new IdKey(getClass(), _scope, key); } @Override public Integer generateId(Object forPojo) { // 02-Apr-2015, tatu: As per [annotations#56], should check for null if (forPojo == null) { return null; } int id = _nextValue; ++_nextValue; return id; } } /** * Implementation that just uses {@link java.util.UUID}s as reliably * unique identifiers: downside is that resulting String is * 36 characters long. *

* One difference to other generators is that scope is always * set as Object.class (regardless of arguments): this * because UUIDs are globally unique, and scope has no meaning. */ public final static class UUIDGenerator extends Base { private static final long serialVersionUID = 1L; public UUIDGenerator() { this(Object.class); } private UUIDGenerator(Class scope) { super(Object.class); } /** * Can just return base instance since this is essentially scopeless */ @Override public ObjectIdGenerator forScope(Class scope) { return this; } /** * Can just return base instance since this is essentially scopeless */ @Override public ObjectIdGenerator newForSerialization(Object context) { return this; } @Override public UUID generateId(Object forPojo) { return UUID.randomUUID(); } @Override public IdKey key(Object key) { // 02-Apr-2015, tatu: As per [annotations#56], should check for null if (key == null) { return null; } return new IdKey(getClass(), null, key); } /** * Since UUIDs are always unique, let's fully ignore scope definition */ @Override public boolean canUseFor(ObjectIdGenerator gen) { return (gen.getClass() == getClass()); } } /** * Implementation that will accept arbitrary (but unique) String Ids on * deserialization, and (by default) use random UUID generation similar * to {@link UUIDGenerator} for generation ids. *

* This generator is most useful for cases where another system creates * String Ids (of arbitrary structure, if any), and Jackson only needs to * keep track of id-to-Object mapping. Generation also works, although if * UUIDs are always used, {@link UUIDGenerator} is a better match as it * will also validate ids being used. * * @since 2.7 */ public final static class StringIdGenerator extends Base { private static final long serialVersionUID = 1L; public StringIdGenerator() { this(Object.class); } private StringIdGenerator(Class scope) { super(Object.class); } // Can just return base instance since this is essentially scopeless @Override public ObjectIdGenerator forScope(Class scope) { return this; } // Can just return base instance since this is essentially scopeless @Override public ObjectIdGenerator newForSerialization(Object context) { return this; } @Override public String generateId(Object forPojo) { return UUID.randomUUID().toString(); } @Override public IdKey key(Object key) { if (key == null) { return null; } return new IdKey(getClass(), null, key); } // Should be usable for generic Opaque String ids? @Override public boolean canUseFor(ObjectIdGenerator gen) { return (gen instanceof StringIdGenerator); } } } ObjectIdResolver.java000066400000000000000000000042501323177441000365070ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey; /** * Definition of API used for resolving actual Java object from * Object Identifiers (as annotated using {@link JsonIdentityInfo}). * * @since 2.4 */ public interface ObjectIdResolver { /** * Method called when a POJO is deserialized and has an Object Identifier. * Method exists so that implementation can keep track of existing object in * JSON stream that could be useful for further resolution. * * @param id The Object Identifer * @param pojo The POJO associated to that Identifier */ void bindItem(IdKey id, Object pojo); /** * Method called when deserialization encounters the given Object Identifier * and requires the POJO associated with it. * * @param id The Object Identifier * @return The POJO, or null if unable to resolve. */ Object resolveId(IdKey id); /** * Factory method called to create a new instance to use for * deserialization: needed since resolvers may have state (a pool of * objects). *

* Note that actual type of 'context' is * com.fasterxml.jackson.databind.DeserializationContext, but * can not be declared here as type itself (as well as call to this object) * comes from databind package. * * @param context * Deserialization context object used (of type * com.fasterxml.jackson.databind.DeserializationContext * ; may be needed by more complex resolvers to access contextual * information such as configuration. */ ObjectIdResolver newForDeserialization(Object context); /** * Method called to check whether this resolver instance can be used for * Object Ids of specific resolver type; determination is based by passing a * configured "blueprint" (prototype) instance; from which the actual * instances are created (using {@link #newForDeserialization}). * * @return True if this instance can be used as-is; false if not */ boolean canUseFor(ObjectIdResolver resolverType); } OptBoolean.java000066400000000000000000000034071323177441000353470ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; /** * Optional Boolean value ("nullean"). Needed just because Java annotations * can not take 'null' as a value (even as default), so there is no * way to distinguish between explicit `true` and `false`, and lack of * choice (related: annotations are limited to primitives, so * {@link java.lang.Boolean} not allowed as solution). *

* Note: although use of `true` and `false` would be more convenient, they * can not be chosen since they are Java keyword and compiler won't allow * the choice. And since enum naming convention suggests all-upper-case, * that is what is done here. * * @since 2.6 */ public enum OptBoolean { /** * Value that indicates that the annotation property is explicitly defined to * be enabled, or true. */ TRUE, /** * Value that indicates that the annotation property is explicitly defined to * be disabled, or false. */ FALSE, /** * Value that indicates that the annotation property does NOT have an explicit * definition of enabled/disabled (or true/false); instead, a higher-level * configuration value is used; or lacking higher-level global setting, * default. */ DEFAULT; public Boolean asBoolean() { if (this == DEFAULT) return null; return (this == TRUE) ? Boolean.TRUE : Boolean.FALSE; } public boolean asPrimitive() { return (this == TRUE); } public static OptBoolean fromBoolean(Boolean b) { if (b == null) { return DEFAULT; } return b.booleanValue() ? TRUE : FALSE; } public static boolean equals(Boolean b1, Boolean b2) { if (b1 == null) { return (b2 == null); } return b1.equals(b2); } } PropertyAccessor.java000066400000000000000000000050631323177441000366140ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; /** * Enumeration used to define kinds of elements (called "property accessors") * that annotations like {@link JsonAutoDetect} apply to. *

* In addition to method types (GETTER/IS_GETTER, SETTER, CREATOR) and the * field type (FIELD), 2 pseudo-types * are defined for convenience: ALWAYS and NONE. These * can be used to indicate, all or none of available method types (respectively), * for use by annotations that takes JsonMethod argument. */ public enum PropertyAccessor { /** * Getters are methods used to get a POJO field value for serialization, * or, under certain conditions also for de-serialization. Latter * can be used for effectively setting Collection or Map values * in absence of setters, iff returned value is not a copy but * actual value of the logical property. *

* Since version 1.3, this does NOT include "is getters" (methods * that return boolean and named 'isXxx' for property 'xxx'); instead, * {@link #IS_GETTER} is used}. */ GETTER, /** * Setters are methods used to set a POJO value for deserialization. */ SETTER, /** * Creators are constructors and (static) factory methods used to * construct POJO instances for deserialization */ CREATOR, /** * Field refers to fields of regular Java objects. Although * they are not really methods, addition of optional field-discovery * in version 1.1 meant that there was need to enable/disable * their auto-detection, and this is the place to add it in. */ FIELD, /** * "Is getters" are getter-like methods that are named "isXxx" * (instead of "getXxx" for getters) and return boolean value * (either primitive, or {@link java.lang.Boolean}). * */ IS_GETTER, /** * This pseudo-type indicates that none of accessors if affected. */ NONE, /** * This pseudo-type indicates that all accessors are affected. */ ALL ; private PropertyAccessor() { } public boolean creatorEnabled() { return (this == CREATOR) || (this == ALL); } public boolean getterEnabled() { return (this == GETTER) || (this == ALL); } public boolean isGetterEnabled() { return (this == IS_GETTER) || (this == ALL); } public boolean setterEnabled() { return (this == SETTER) || (this == ALL); } public boolean fieldEnabled() { return (this == FIELD) || (this == ALL); } } SimpleObjectIdResolver.java000066400000000000000000000025111323177441000376570ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey; /** * Simple implementation of {@link ObjectIdResolver} * * @author Pascal Gélinas */ public class SimpleObjectIdResolver implements ObjectIdResolver { protected Map _items; public SimpleObjectIdResolver() { } @Override public void bindItem(IdKey id, Object ob) { if (_items == null) { _items = new HashMap(); } else if (_items.containsKey(id)) { throw new IllegalStateException("Already had POJO for id (" + id.key.getClass().getName() + ") [" + id + "]"); } _items.put(id, ob); } @Override public Object resolveId(IdKey id) { return (_items == null) ? null : _items.get(id); } @Override public boolean canUseFor(ObjectIdResolver resolverType) { return resolverType.getClass() == getClass(); } @Override public ObjectIdResolver newForDeserialization(Object context) { // 19-Dec-2014, tatu: Important: must re-create without existing mapping; otherwise bindings leak // (and worse, cause unnecessary memory retention) return new SimpleObjectIdResolver(); } } package-info.java000066400000000000000000000011061323177441000356230ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/java/com/fasterxml/jackson/annotation/** * Public core annotations, most of which are used to configure how * Data Mapping/Binding works. Annotations in this package can only * have dependencies to non-annotation classes in Core package; * annotations that have dependencies to Mapper classes are included * in Mapper module (under org.codehaus.jackson.map.annotate). * Also contains parameter types (mostly enums) needed by annotations. *

* Note that prior versions (1.x) contained these annotations within * 'core' jar, as part of Streaming API. */ package com.fasterxml.jackson.annotation; jackson-annotations-jackson-annotations-2.9.4/src/main/resources/000077500000000000000000000000001323177441000252215ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/resources/META-INF/000077500000000000000000000000001323177441000263615ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/main/resources/META-INF/LICENSE000066400000000000000000000004751323177441000273740ustar00rootroot00000000000000This copy of Jackson JSON processor annotations is licensed under the Apache (Software) License, version 2.0 ("the License"). See the License for details about distribution rights, and the specific rights regarding derivate works. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0 jackson-annotations-jackson-annotations-2.9.4/src/test/000077500000000000000000000000001323177441000232425ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/000077500000000000000000000000001323177441000241635ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/000077500000000000000000000000001323177441000247415ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/000077500000000000000000000000001323177441000267465ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/000077500000000000000000000000001323177441000303765ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotation/000077500000000000000000000000001323177441000325505ustar00rootroot00000000000000FormatTest.java000066400000000000000000000215611323177441000354310ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import com.fasterxml.jackson.annotation.JsonFormat.Feature; import com.fasterxml.jackson.annotation.JsonFormat.Shape; /** * Tests to verify that it is possibly to merge {@link JsonFormat.Value} * instances for overrides. */ public class FormatTest extends TestBase { private final JsonFormat.Value EMPTY = JsonFormat.Value.empty(); @JsonFormat(shape=JsonFormat.Shape.BOOLEAN, pattern="xyz", timezone="bogus") private final static class Bogus { } public void testEmptyInstanceDefaults() { JsonFormat.Value empty = JsonFormat.Value.empty(); for (Feature f : Feature.values()) { assertNull(empty.getFeature(f)); } assertFalse(empty.hasLocale()); assertFalse(empty.hasPattern()); assertFalse(empty.hasShape()); assertFalse(empty.hasTimeZone()); assertFalse(empty.hasLenient()); assertFalse(empty.isLenient()); } public void testEquality() { assertTrue(EMPTY.equals(EMPTY)); assertTrue(new JsonFormat.Value().equals(new JsonFormat.Value())); JsonFormat.Value v1 = JsonFormat.Value.forShape(Shape.BOOLEAN); JsonFormat.Value v2 = JsonFormat.Value.forShape(Shape.BOOLEAN); JsonFormat.Value v3 = JsonFormat.Value.forShape(Shape.SCALAR); assertTrue(v1.equals(v2)); assertTrue(v2.equals(v1)); assertFalse(v1.equals(v3)); assertFalse(v3.equals(v1)); assertFalse(v2.equals(v3)); assertFalse(v3.equals(v2)); // not strictly guaranteed but... assertFalse(v1.hashCode() == v3.hashCode()); // then let's converge assertEquals(v1, v3.withShape(Shape.BOOLEAN)); assertFalse(v1.equals(v1.withPattern("ZBC"))); assertFalse(v1.equals(v1.withFeature(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY))); assertFalse(v1.equals(v1.withoutFeature(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY))); } public void testToString() { assertEquals("JsonFormat.Value(pattern=null,shape=STRING,lenient=null,locale=null,timezone=null,features=EMPTY)", JsonFormat.Value.forShape(JsonFormat.Shape.STRING).toString()); assertEquals("JsonFormat.Value(pattern=[.],shape=ANY,lenient=null,locale=null,timezone=null,features=EMPTY)", JsonFormat.Value.forPattern("[.]").toString()); } public void testFromAnnotation() { JsonFormat ann = Bogus.class.getAnnotation(JsonFormat.class); JsonFormat.Value v = JsonFormat.Value.from(ann); assertEquals("xyz", v.getPattern()); assertEquals(JsonFormat.Shape.BOOLEAN, v.getShape()); // note: since it's not valid, should not try access as real thing assertEquals("bogus", v.timeZoneAsString()); // also: assertSame(EMPTY, JsonFormat.Value.from(null)); } public void testSimpleMerge() { // Start with an empty instance assertFalse(EMPTY.hasLocale()); assertFalse(EMPTY.hasPattern()); assertFalse(EMPTY.hasShape()); assertFalse(EMPTY.hasTimeZone()); assertNull(EMPTY.getLocale()); // then with a non-empty one final String TEST_PATTERN = "format-string"; // not parsed, usage varies JsonFormat.Value v = JsonFormat.Value.forPattern(TEST_PATTERN); assertTrue(v.hasPattern()); assertEquals(TEST_PATTERN, v.getPattern()); assertFalse(v.hasLocale()); assertFalse(v.hasShape()); assertFalse(v.hasTimeZone()); // and ensure nothing overridden with empty JsonFormat.Value merged = v.withOverrides(EMPTY); assertEquals(TEST_PATTERN, merged.getPattern()); assertFalse(merged.hasLocale()); assertFalse(merged.hasShape()); assertFalse(merged.hasTimeZone()); // minor optimization: overriding with itself has no effect assertSame(merged, merged.withOverrides(merged)); // but that empty is overridden merged = JsonFormat.Value.merge(EMPTY, v); assertEquals(TEST_PATTERN, merged.getPattern()); assertFalse(merged.hasLocale()); assertFalse(merged.hasShape()); assertFalse(merged.hasTimeZone()); // also some shortcuts: assertSame(merged, merged.withOverrides(null)); // then with some other combinations final JsonFormat.Shape TEST_SHAPE = JsonFormat.Shape.NUMBER; JsonFormat.Value v2 = JsonFormat.Value.forShape(TEST_SHAPE); merged = v.withOverrides(v2); assertEquals(TEST_PATTERN, merged.getPattern()); assertFalse(merged.hasLocale()); assertEquals(TEST_SHAPE, merged.getShape()); assertFalse(merged.hasTimeZone()); merged = v2.withOverrides(v); assertEquals(TEST_PATTERN, merged.getPattern()); assertFalse(merged.hasLocale()); assertEquals(TEST_SHAPE, merged.getShape()); assertFalse(merged.hasTimeZone()); } public void testMultiMerge() { final String TEST_PATTERN = "format-string"; // not parsed, usage varies JsonFormat.Value format2 = JsonFormat.Value.forPattern(TEST_PATTERN); JsonFormat.Value format3 = JsonFormat.Value.forLeniency(Boolean.FALSE); JsonFormat.Value merged = JsonFormat.Value.mergeAll(EMPTY, format2, format3); assertEquals(TEST_PATTERN, merged.getPattern()); assertEquals(Boolean.FALSE, merged.getLenient()); } /* /********************************************************** /* Test specific value properties /********************************************************** */ public void testLeniency() { JsonFormat.Value empty = JsonFormat.Value.empty(); assertFalse(empty.hasLenient()); assertFalse(empty.isLenient()); assertNull(empty.getLenient()); JsonFormat.Value lenient = empty.withLenient(Boolean.TRUE); assertTrue(lenient.hasLenient()); assertTrue(lenient.isLenient()); assertEquals(Boolean.TRUE, lenient.getLenient()); assertTrue(lenient.equals(lenient)); assertFalse(empty.equals(lenient)); assertFalse(lenient.equals(empty)); // should NOT create now one if no change: assertSame(lenient, lenient.withLenient(Boolean.TRUE)); JsonFormat.Value strict = lenient.withLenient(Boolean.FALSE); assertTrue(strict.hasLenient()); assertFalse(strict.isLenient()); assertEquals(Boolean.FALSE, strict.getLenient()); assertTrue(strict.equals(strict)); assertFalse(empty.equals(strict)); assertFalse(strict.equals(empty)); assertFalse(lenient.equals(strict)); assertFalse(strict.equals(lenient)); // and finally, can also clear up setting JsonFormat.Value dunno = lenient.withLenient(null); assertFalse(dunno.hasLenient()); assertFalse(dunno.isLenient()); assertNull(dunno.getLenient()); assertTrue(empty.equals(dunno)); assertTrue(dunno.equals(empty)); assertFalse(lenient.equals(dunno)); assertFalse(dunno.equals(lenient)); } public void testShape() { assertFalse(JsonFormat.Shape.STRING.isNumeric()); assertFalse(JsonFormat.Shape.STRING.isStructured()); assertTrue(JsonFormat.Shape.NUMBER_INT.isNumeric()); assertTrue(JsonFormat.Shape.NUMBER_FLOAT.isNumeric()); assertTrue(JsonFormat.Shape.NUMBER.isNumeric()); assertTrue(JsonFormat.Shape.ARRAY.isStructured()); assertTrue(JsonFormat.Shape.OBJECT.isStructured()); } public void testFeatures() { JsonFormat.Features f1 = JsonFormat.Features.empty(); JsonFormat.Features f2 = f1.with(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) .without(Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS); assertTrue(f1.equals(f1)); assertFalse(f1.equals(f2)); assertFalse(f1.equals(null)); assertFalse(f1.equals("foo")); assertNull(f1.get(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)); assertEquals(Boolean.TRUE, f2.get(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)); assertNull(f1.get(Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)); assertEquals(Boolean.FALSE, f2.get(Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)); JsonFormat.Features f3 = f1.withOverrides(f2); assertEquals(Boolean.TRUE, f3.get(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)); assertEquals(Boolean.FALSE, f3.get(Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)); // switch values around JsonFormat.Features f4 = JsonFormat.Features.construct( new Feature[] { // enabled: Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS }, new Feature[] { // enabled Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY }); assertEquals(Boolean.FALSE, f4.get(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)); assertEquals(Boolean.TRUE, f4.get(Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)); } } IncludeTest.java000066400000000000000000000135101323177441000355570ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import com.fasterxml.jackson.annotation.JsonInclude.Include; /** * Tests to verify that it is possibly to merge {@link JsonInclude.Value} * instances for overrides */ public class IncludeTest extends TestBase { private final JsonInclude.Value EMPTY = JsonInclude.Value.empty(); @JsonInclude(value=JsonInclude.Include.NON_EMPTY, content=JsonInclude.Include.NON_DEFAULT) private final static class Bogus { } @JsonInclude(value=JsonInclude.Include.CUSTOM, valueFilter=Integer.class, content=JsonInclude.Include.CUSTOM, contentFilter=Long.class) private final static class Custom { } public void testEquality() { assertTrue(EMPTY.equals(EMPTY)); JsonInclude.Value v1 = JsonInclude.Value.construct(Include.NON_ABSENT, null); JsonInclude.Value v2 = JsonInclude.Value.construct(Include.NON_ABSENT, null); JsonInclude.Value v3 = JsonInclude.Value.construct(Include.NON_ABSENT, Include.NON_EMPTY); assertTrue(v1.equals(v2)); assertTrue(v2.equals(v1)); assertFalse(v1.equals(v3)); assertFalse(v3.equals(v1)); assertFalse(v2.equals(v3)); assertFalse(v3.equals(v2)); } public void testFromAnnotation() { JsonInclude ann = Bogus.class.getAnnotation(JsonInclude.class); JsonInclude.Value v = JsonInclude.Value.from(ann); assertEquals(Include.NON_EMPTY, v.getValueInclusion()); assertEquals(Include.NON_DEFAULT, v.getContentInclusion()); } public void testFromAnnotationWithCustom() { JsonInclude ann = Custom.class.getAnnotation(JsonInclude.class); JsonInclude.Value v = JsonInclude.Value.from(ann); assertEquals(Include.CUSTOM, v.getValueInclusion()); assertEquals(Include.CUSTOM, v.getContentInclusion()); assertEquals(Integer.class, v.getValueFilter()); assertEquals(Long.class, v.getContentFilter()); assertEquals( "JsonInclude.Value(value=CUSTOM,content=CUSTOM,valueFilter=java.lang.Integer.class,contentFilter=java.lang.Long.class)", v.toString()); } public void testStdOverrides() { assertEquals("JsonInclude.Value(value=NON_ABSENT,content=USE_DEFAULTS)", JsonInclude.Value.construct(Include.NON_ABSENT, null).toString()); int x = EMPTY.hashCode(); if (x == 0) { fail(); } assertFalse(EMPTY.equals(null)); assertFalse(EMPTY.equals("")); } public void testSimpleMerge() { JsonInclude.Value empty = JsonInclude.Value.empty(); assertEquals(Include.USE_DEFAULTS, empty.getValueInclusion()); assertEquals(Include.USE_DEFAULTS, empty.getContentInclusion()); JsonInclude.Value v2 = empty.withValueInclusion(Include.NON_ABSENT); assertEquals(Include.NON_ABSENT, v2.getValueInclusion()); assertEquals(Include.USE_DEFAULTS, v2.getContentInclusion()); JsonInclude.Value v3 = new JsonInclude.Value(Include.NON_EMPTY, Include.ALWAYS, null, null); assertEquals(Include.NON_EMPTY, v3.getValueInclusion()); assertEquals(Include.ALWAYS, v3.getContentInclusion()); // Ok; but then overrides, which should skip 'USE_DEFAULT' overrides JsonInclude.Value merged = v3.withOverrides(empty); // no overrides with "empty": assertEquals(v3.getValueInclusion(), merged.getValueInclusion()); assertEquals(v3.getContentInclusion(), merged.getContentInclusion()); // but other values ought to be overridden (value, yes, content, no because it's default) merged = JsonInclude.Value.merge(v3, v2); assertEquals(v2.getValueInclusion(), merged.getValueInclusion()); assertEquals(v3.getContentInclusion(), merged.getContentInclusion()); merged = JsonInclude.Value.mergeAll(empty, v3); assertEquals(v3.getValueInclusion(), merged.getValueInclusion()); assertEquals(v3.getContentInclusion(), merged.getContentInclusion()); } // for [annotations#76] public void testContentMerge76() { JsonInclude.Value v1 = JsonInclude.Value.empty() .withContentInclusion(JsonInclude.Include.ALWAYS) .withValueInclusion(JsonInclude.Include.NON_ABSENT); JsonInclude.Value v2 = JsonInclude.Value.empty() .withContentInclusion(JsonInclude.Include.NON_EMPTY) .withValueInclusion(JsonInclude.Include.USE_DEFAULTS); JsonInclude.Value v12 = v2.withOverrides(v1); // v1 priority JsonInclude.Value v21 = v1.withOverrides(v2); // v2 priority assertEquals(JsonInclude.Include.ALWAYS, v12.getContentInclusion()); assertEquals(JsonInclude.Include.NON_ABSENT, v12.getValueInclusion()); assertEquals(JsonInclude.Include.NON_EMPTY, v21.getContentInclusion()); assertEquals(JsonInclude.Include.NON_ABSENT, v21.getValueInclusion()); } public void testFilters() { JsonInclude.Value empty = JsonInclude.Value.empty(); assertNull(empty.getValueFilter()); assertNull(empty.getContentFilter()); // note: filter class choices are arbitrary, just confirming assingments JsonInclude.Value v1 = empty.withValueFilter(String.class); assertEquals(JsonInclude.Include.CUSTOM, v1.getValueInclusion()); assertEquals(String.class, v1.getValueFilter()); assertNull(v1.withValueFilter(null).getValueFilter()); assertNull(v1.withValueFilter(Void.class).getValueFilter()); JsonInclude.Value v2 = empty.withContentFilter(Long.class); assertEquals(JsonInclude.Include.CUSTOM, v2.getContentInclusion()); assertEquals(Long.class, v2.getContentFilter()); assertNull(v2.withContentFilter(null).getContentFilter()); assertNull(v2.withContentFilter(Void.class).getContentFilter()); } } JacksonInjectTest.java000066400000000000000000000046271323177441000367320ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; public class JacksonInjectTest extends TestBase { private final static class Bogus { @JacksonInject(value="inject", useInput=OptBoolean.FALSE) public int field; @JacksonInject public int vanilla; } private final JacksonInject.Value EMPTY = JacksonInject.Value.empty(); public void testEmpty() { assertNull(EMPTY.getId()); assertNull(EMPTY.getUseInput()); assertTrue(EMPTY.willUseInput(true)); assertFalse(EMPTY.willUseInput(false)); assertSame(EMPTY, JacksonInject.Value.construct(null, null)); // also, "" gets coerced to null so assertSame(EMPTY, JacksonInject.Value.construct("", null)); } public void testFromAnnotation() throws Exception { assertSame(EMPTY, JacksonInject.Value.from(null)); // legal JacksonInject ann = Bogus.class.getField("field").getAnnotation(JacksonInject.class); JacksonInject.Value v = JacksonInject.Value.from(ann); assertEquals("inject", v.getId()); assertEquals(Boolean.FALSE, v.getUseInput()); assertEquals("JacksonInject.Value(id=inject,useInput=false)", v.toString()); assertFalse(v.equals(EMPTY)); assertFalse(EMPTY.equals(v)); JacksonInject ann2 = Bogus.class.getField("vanilla").getAnnotation(JacksonInject.class); v = JacksonInject.Value.from(ann2); assertSame(EMPTY, v); } public void testStdMethods() { assertEquals("JacksonInject.Value(id=null,useInput=null)", EMPTY.toString()); int x = EMPTY.hashCode(); if (x == 0) { // no fixed value, but should not evalute to 0 fail(); } assertEquals(EMPTY, EMPTY); assertFalse(EMPTY.equals(null)); assertFalse(EMPTY.equals("xyz")); } public void testFactories() throws Exception { JacksonInject.Value v = EMPTY.withId("name"); assertNotSame(EMPTY, v); assertEquals("name", v.getId()); assertSame(v, v.withId("name")); JacksonInject.Value v2 = v.withUseInput(Boolean.TRUE); assertNotSame(v, v2); assertFalse(v.equals(v2)); assertFalse(v2.equals(v)); assertSame(v2, v2.withUseInput(Boolean.TRUE)); int x = v2.hashCode(); if (x == 0) { // no fixed value, but should not evalute to 0 fail(); } } } JsonIgnorePropertiesTest.java000066400000000000000000000132771323177441000403400ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.util.*; /** * Tests to verify that it is possibly to merge {@link JsonIgnoreProperties.Value} * instances for overrides */ public class JsonIgnorePropertiesTest extends TestBase { @JsonIgnoreProperties(value={ "foo", "bar" }, ignoreUnknown=true) private final static class Bogus { } private final JsonIgnoreProperties.Value EMPTY = JsonIgnoreProperties.Value.empty(); public void testEmpty() { // ok to try to create from null; gives empty assertSame(EMPTY, JsonIgnoreProperties.Value.from(null)); assertEquals(0, EMPTY.getIgnored().size()); assertFalse(EMPTY.getAllowGetters()); assertFalse(EMPTY.getAllowSetters()); } public void testEquality() { assertEquals(EMPTY, EMPTY); // empty has "merge" set to 'true' so: assertSame(EMPTY, EMPTY.withMerge()); JsonIgnoreProperties.Value v = EMPTY.withoutMerge(); assertEquals(v, v); assertFalse(EMPTY.equals(v)); assertFalse(v.equals(EMPTY)); } public void testFromAnnotation() throws Exception { JsonIgnoreProperties.Value v = JsonIgnoreProperties.Value.from( Bogus.class.getAnnotation(JsonIgnoreProperties.class)); assertNotNull(v); assertFalse(v.getMerge()); assertFalse(v.getAllowGetters()); assertFalse(v.getAllowSetters()); Set ign = v.getIgnored(); assertEquals(2, v.getIgnored().size()); assertEquals(_set("foo", "bar"), ign); } public void testFactories() { assertSame(EMPTY, JsonIgnoreProperties.Value.forIgnoreUnknown(false)); assertSame(EMPTY, JsonIgnoreProperties.Value.forIgnoredProperties()); assertSame(EMPTY, JsonIgnoreProperties.Value.forIgnoredProperties(Collections.emptySet())); JsonIgnoreProperties.Value v = JsonIgnoreProperties.Value.forIgnoredProperties("a", "b"); assertEquals(_set("a", "b"), v.getIgnored()); JsonIgnoreProperties.Value vser = v.withAllowGetters(); assertTrue(vser.getAllowGetters()); assertFalse(vser.getAllowSetters()); assertEquals(_set("a", "b"), vser.getIgnored()); assertEquals(_set("a", "b"), vser.findIgnoredForDeserialization()); assertEquals(_set(), vser.findIgnoredForSerialization()); JsonIgnoreProperties.Value vdeser = v.withAllowSetters(); assertFalse(vdeser.getAllowGetters()); assertTrue(vdeser.getAllowSetters()); assertEquals(_set("a", "b"), vdeser.getIgnored()); assertEquals(_set(), vdeser.findIgnoredForDeserialization()); assertEquals(_set("a", "b"), vdeser.findIgnoredForSerialization()); } public void testMutantFactories() { assertEquals(2, EMPTY.withIgnored("a", "b").getIgnored().size()); assertEquals(1, EMPTY.withIgnored(Collections.singleton("x")).getIgnored().size()); assertEquals(0, EMPTY.withIgnored((Set) null).getIgnored().size()); assertTrue(EMPTY.withIgnoreUnknown().getIgnoreUnknown()); assertFalse(EMPTY.withoutIgnoreUnknown().getIgnoreUnknown()); assertTrue(EMPTY.withAllowGetters().getAllowGetters()); assertFalse(EMPTY.withoutAllowGetters().getAllowGetters()); assertTrue(EMPTY.withAllowSetters().getAllowSetters()); assertFalse(EMPTY.withoutAllowSetters().getAllowSetters()); assertTrue(EMPTY.withMerge().getMerge()); assertFalse(EMPTY.withoutMerge().getMerge()); } public void testSimpleMerge() { JsonIgnoreProperties.Value v1 = EMPTY.withIgnoreUnknown().withAllowGetters(); JsonIgnoreProperties.Value v2a = EMPTY.withMerge() .withIgnored("a"); JsonIgnoreProperties.Value v2b = EMPTY.withoutMerge(); // when merging, should just have union of things JsonIgnoreProperties.Value v3a = v1.withOverrides(v2a); assertEquals(Collections.singleton("a"), v3a.getIgnored()); assertTrue(v3a.getIgnoreUnknown()); assertTrue(v3a.getAllowGetters()); assertFalse(v3a.getAllowSetters()); // when NOT merging, simply replacing values JsonIgnoreProperties.Value v3b = JsonIgnoreProperties.Value.merge(v1, v2b); assertEquals(Collections.emptySet(), v3b.getIgnored()); assertFalse(v3b.getIgnoreUnknown()); assertFalse(v3b.getAllowGetters()); assertFalse(v3b.getAllowSetters()); // and effectively really just uses overrides as is assertEquals(v2b, v3b); assertSame(v2b, v2b.withOverrides(null)); assertSame(v2b, v2b.withOverrides(EMPTY)); } public void testMergeIgnoreProperties() { JsonIgnoreProperties.Value v1 = EMPTY.withIgnored("a"); JsonIgnoreProperties.Value v2 = EMPTY.withIgnored("b"); JsonIgnoreProperties.Value v3 = EMPTY.withIgnored("c"); JsonIgnoreProperties.Value merged = JsonIgnoreProperties.Value.mergeAll(v1, v2, v3); Set all = merged.getIgnored(); assertEquals(3, all.size()); assertTrue(all.contains("a")); assertTrue(all.contains("b")); assertTrue(all.contains("c")); } public void testToString() { assertEquals( "JsonIgnoreProperties.Value(ignored=[],ignoreUnknown=false,allowGetters=false,allowSetters=true,merge=true)", EMPTY.withAllowSetters() .withMerge() .toString()); int hash = EMPTY.hashCode(); // no real good way to test but... if (hash == 0) { fail("Should not get 0 for hash"); } } private Set _set(String... args) { return new LinkedHashSet(Arrays.asList(args)); } } JsonSetterTest.java000066400000000000000000000063211323177441000362760ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; public class JsonSetterTest extends TestBase { private final static class Bogus { @JsonSetter(nulls=Nulls.FAIL, contentNulls=Nulls.SKIP) public int field; } private final JsonSetter.Value EMPTY = JsonSetter.Value.empty(); public void testEmpty() { assertEquals(Nulls.DEFAULT, EMPTY.getValueNulls()); assertEquals(Nulls.DEFAULT, EMPTY.getContentNulls()); assertEquals(JsonSetter.class, EMPTY.valueFor()); assertNull(EMPTY.nonDefaultValueNulls()); assertNull(EMPTY.nonDefaultContentNulls()); } public void testStdMethods() { assertEquals("JsonSetter.Value(valueNulls=DEFAULT,contentNulls=DEFAULT)", EMPTY.toString()); int x = EMPTY.hashCode(); if (x == 0) { // no fixed value, but should not evalute to 0 fail(); } assertEquals(EMPTY, EMPTY); assertFalse(EMPTY.equals(null)); assertFalse(EMPTY.equals("xyz")); } public void testFromAnnotation() throws Exception { assertSame(EMPTY, JsonSetter.Value.from(null)); // legal JsonSetter ann = Bogus.class.getField("field").getAnnotation(JsonSetter.class); JsonSetter.Value v = JsonSetter.Value.from(ann); assertEquals(Nulls.FAIL, v.getValueNulls()); assertEquals(Nulls.SKIP, v.getContentNulls()); } public void testConstruct() throws Exception { JsonSetter.Value v = JsonSetter.Value.construct(null, null); assertSame(EMPTY, v); } public void testFactories() throws Exception { JsonSetter.Value v = JsonSetter.Value.forContentNulls(Nulls.SET); assertEquals(Nulls.DEFAULT, v.getValueNulls()); assertEquals(Nulls.SET, v.getContentNulls()); assertEquals(Nulls.SET, v.nonDefaultContentNulls()); JsonSetter.Value skip = JsonSetter.Value.forValueNulls(Nulls.SKIP); assertEquals(Nulls.SKIP, skip.getValueNulls()); assertEquals(Nulls.DEFAULT, skip.getContentNulls()); assertEquals(Nulls.SKIP, skip.nonDefaultValueNulls()); } public void testSimpleMerge() { JsonSetter.Value v = EMPTY.withContentNulls(Nulls.SKIP); assertEquals(Nulls.SKIP, v.getContentNulls()); v = v.withValueNulls(Nulls.FAIL); assertEquals(Nulls.FAIL, v.getValueNulls()); } public void testWithMethods() { JsonSetter.Value v = EMPTY.withContentNulls(null); assertSame(EMPTY, v); v = v.withContentNulls(Nulls.FAIL); assertEquals(Nulls.FAIL, v.getContentNulls()); assertSame(v, v.withContentNulls(Nulls.FAIL)); JsonSetter.Value v2 = v.withValueNulls(Nulls.SKIP); assertEquals(Nulls.SKIP, v2.getValueNulls()); assertFalse(v.equals(v2)); assertFalse(v2.equals(v)); JsonSetter.Value v3 = v2.withValueNulls(null, null); assertEquals(Nulls.DEFAULT, v3.getContentNulls()); assertEquals(Nulls.DEFAULT, v3.getValueNulls()); assertSame(v3, v3.withValueNulls(null, null)); JsonSetter.Value merged = v3.withOverrides(v2); assertNotSame(v2, merged); assertEquals(merged, v2); assertEquals(v2, merged); } } ObjectIdStuffTest.java000066400000000000000000000027431323177441000366750ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.util.UUID; // Test mostly to keep code coverage decent public class ObjectIdStuffTest extends TestBase { public void testObjectIdGenerator() { ObjectIdGenerator.IdKey k = new ObjectIdGenerator.IdKey(String.class, Object.class, "id1"); int h = k.hashCode(); if (h == 0) { fail("Should not produce 0 as hash"); } assertTrue(k.equals(k)); assertEquals("[ObjectId: key=id1, type=java.lang.String, scope=java.lang.Object]", k.toString()); ObjectIdGenerator.IdKey k2 = new ObjectIdGenerator.IdKey(Integer.class, Object.class, "id2"); assertFalse(k.equals(k2)); assertFalse(k2.equals(k)); } public void testIntSequenceGenerator() { ObjectIdGenerators.IntSequenceGenerator gen = new ObjectIdGenerators.IntSequenceGenerator(); Integer id = gen.generateId("foo"); assertEquals(Integer.valueOf(-1), id); id = gen.generateId("foo"); assertEquals(Integer.valueOf(0), id); } public void testStringIdGenerator() { ObjectIdGenerators.StringIdGenerator gen = new ObjectIdGenerators.StringIdGenerator(); String id = gen.generateId("foo"); assertNotNull(id); } public void testUUIDGenerator() { ObjectIdGenerators.UUIDGenerator gen = new ObjectIdGenerators.UUIDGenerator(); UUID id = gen.generateId("foo"); assertNotNull(id); } } OptBooleanTest.java000066400000000000000000000007411323177441000362400ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; // Silly test for OptBoolean, for code coverage public class OptBooleanTest extends TestBase { public void testProperties() { assertTrue(OptBoolean.TRUE.asPrimitive()); assertFalse(OptBoolean.FALSE.asPrimitive()); assertFalse(OptBoolean.DEFAULT.asPrimitive()); assertSame(OptBoolean.FALSE, OptBoolean.fromBoolean(false)); assertSame(OptBoolean.TRUE, OptBoolean.fromBoolean(true)); } } PropertyAccessorTest.java000066400000000000000000000021371323177441000375060ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; // Silly test for PropertyAccessor, for code coverage public class PropertyAccessorTest extends TestBase { public void testProperties() { assertTrue(PropertyAccessor.ALL.creatorEnabled()); assertTrue(PropertyAccessor.CREATOR.creatorEnabled()); assertTrue(PropertyAccessor.CREATOR.creatorEnabled()); assertTrue(PropertyAccessor.ALL.getterEnabled()); assertTrue(PropertyAccessor.GETTER.getterEnabled()); assertFalse(PropertyAccessor.CREATOR.getterEnabled()); assertTrue(PropertyAccessor.ALL.isGetterEnabled()); assertTrue(PropertyAccessor.IS_GETTER.isGetterEnabled()); assertFalse(PropertyAccessor.CREATOR.isGetterEnabled()); assertTrue(PropertyAccessor.ALL.setterEnabled()); assertTrue(PropertyAccessor.SETTER.setterEnabled()); assertFalse(PropertyAccessor.CREATOR.setterEnabled()); assertTrue(PropertyAccessor.ALL.fieldEnabled()); assertTrue(PropertyAccessor.FIELD.fieldEnabled()); assertFalse(PropertyAccessor.CREATOR.fieldEnabled()); } } TestBase.java000066400000000000000000000002011323177441000350370ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import junit.framework.TestCase; public abstract class TestBase extends TestCase { } VisibilityTest.java000066400000000000000000000156351323177441000363350ustar00rootroot00000000000000jackson-annotations-jackson-annotations-2.9.4/src/test/java/com/fasterxml/jackson/annotationpackage com.fasterxml.jackson.annotation; import java.lang.reflect.Member; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; // Silly test for JsonAutoDetect.Visibility type, for code coverage public class VisibilityTest extends TestBase { static class Bogus { public String value; } @JsonAutoDetect(fieldVisibility=Visibility.NON_PRIVATE, getterVisibility=Visibility.PROTECTED_AND_PUBLIC, isGetterVisibility=Visibility.NONE, setterVisibility=Visibility.PUBLIC_ONLY, creatorVisibility=Visibility.ANY) private final static class Custom { } private final static JsonAutoDetect.Value NO_OVERRIDES = JsonAutoDetect.Value.noOverrides(); private final static JsonAutoDetect.Value DEFAULTS = JsonAutoDetect.Value.defaultVisibility(); public void testAnnotationProperties() throws Exception { Member m = Bogus.class.getField("value"); assertTrue(JsonAutoDetect.Visibility.ANY.isVisible(m)); assertFalse(JsonAutoDetect.Visibility.NONE.isVisible(m)); assertTrue(JsonAutoDetect.Visibility.NON_PRIVATE.isVisible(m)); assertTrue(JsonAutoDetect.Visibility.PUBLIC_ONLY.isVisible(m)); assertTrue(JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC.isVisible(m)); assertTrue(JsonAutoDetect.Visibility.NON_PRIVATE.isVisible(m)); // forget why DEFAULT would give false but assertFalse(JsonAutoDetect.Visibility.DEFAULT.isVisible(m)); } public void testBasicValueProperties() { JsonAutoDetect.Value v = JsonAutoDetect.Value.DEFAULT; assertEquals(JsonAutoDetect.class, v.valueFor()); // and then standard method override basics... int x = v.hashCode(); if (x == 0) { // not guaranteed in theory but... fail(); } assertTrue(v.equals(v)); // mostly to ensure no NPE or class cast exception: assertFalse(v.equals(null)); assertFalse(v.equals("foo")); } public void testEquality() { assertEquals(NO_OVERRIDES, NO_OVERRIDES); assertEquals(DEFAULTS, DEFAULTS); assertFalse(DEFAULTS.equals(NO_OVERRIDES)); assertFalse(NO_OVERRIDES.equals(DEFAULTS)); } public void testFromAnnotation() { JsonAutoDetect ann = Custom.class.getAnnotation(JsonAutoDetect.class); JsonAutoDetect.Value v = JsonAutoDetect.Value.from(ann); JsonAutoDetect.Value v2 = JsonAutoDetect.Value.from(ann); assertNotSame(v, v2); assertEquals(v, v2); assertEquals(v2, v); assertEquals(ann.fieldVisibility(), v.getFieldVisibility()); assertEquals(ann.getterVisibility(), v.getGetterVisibility()); assertEquals(ann.isGetterVisibility(), v.getIsGetterVisibility()); assertEquals(ann.setterVisibility(), v.getSetterVisibility()); assertEquals(ann.creatorVisibility(), v.getCreatorVisibility()); } public void testToString() { assertEquals( "JsonAutoDetect.Value(fields=PUBLIC_ONLY,getters=PUBLIC_ONLY,"+ "isGetters=PUBLIC_ONLY,setters=ANY,creators=PUBLIC_ONLY)", JsonAutoDetect.Value.defaultVisibility().toString()); assertEquals( "JsonAutoDetect.Value(fields=DEFAULT,getters=DEFAULT,"+ "isGetters=DEFAULT,setters=DEFAULT,creators=DEFAULT)", JsonAutoDetect.Value.noOverrides().toString()); } public void testSimpleMerge() { JsonAutoDetect.Value base = JsonAutoDetect.Value.construct( Visibility.ANY, Visibility.PUBLIC_ONLY, Visibility.ANY, Visibility.NONE, Visibility.ANY); JsonAutoDetect.Value overrides = JsonAutoDetect.Value.construct( Visibility.NON_PRIVATE, Visibility.DEFAULT, Visibility.PUBLIC_ONLY, Visibility.DEFAULT, Visibility.DEFAULT); JsonAutoDetect.Value merged = JsonAutoDetect.Value.merge(base, overrides); assertFalse(merged.equals(base)); assertFalse(merged.equals(overrides)); assertEquals(merged, merged); assertEquals(Visibility.NON_PRIVATE, merged.getFieldVisibility()); assertEquals(Visibility.PUBLIC_ONLY, merged.getGetterVisibility()); assertEquals(Visibility.PUBLIC_ONLY, merged.getIsGetterVisibility()); assertEquals(Visibility.NONE, merged.getSetterVisibility()); assertEquals(Visibility.ANY, merged.getCreatorVisibility()); // try the other way around too merged = JsonAutoDetect.Value.merge(overrides, base); assertEquals(Visibility.ANY, merged.getFieldVisibility()); assertEquals(Visibility.PUBLIC_ONLY, merged.getGetterVisibility()); assertEquals(Visibility.ANY, merged.getIsGetterVisibility()); assertEquals(Visibility.NONE, merged.getSetterVisibility()); assertEquals(Visibility.ANY, merged.getCreatorVisibility()); // plus, special cases assertSame(overrides, JsonAutoDetect.Value.merge(null, overrides)); assertSame(overrides, JsonAutoDetect.Value.merge(overrides, null)); } public void testFactoryMethods() { JsonAutoDetect.Value v = JsonAutoDetect.Value.construct(PropertyAccessor.FIELD, Visibility.ANY); assertEquals(Visibility.ANY, v.getFieldVisibility()); assertEquals(Visibility.DEFAULT, v.getGetterVisibility()); assertEquals(Visibility.DEFAULT, v.getIsGetterVisibility()); assertEquals(Visibility.DEFAULT, v.getSetterVisibility()); assertEquals(Visibility.DEFAULT, v.getCreatorVisibility()); JsonAutoDetect.Value all = JsonAutoDetect.Value.construct(PropertyAccessor.ALL, Visibility.NONE); assertEquals(Visibility.NONE, all.getFieldVisibility()); assertEquals(Visibility.NONE, all.getGetterVisibility()); assertEquals(Visibility.NONE, all.getIsGetterVisibility()); assertEquals(Visibility.NONE, all.getSetterVisibility()); assertEquals(Visibility.NONE, all.getCreatorVisibility()); } public void testSimpleChanges() { assertSame(NO_OVERRIDES, NO_OVERRIDES.withFieldVisibility(Visibility.DEFAULT)); JsonAutoDetect.Value v = NO_OVERRIDES.withCreatorVisibility(Visibility.PUBLIC_ONLY); assertNotSame(NO_OVERRIDES, v); assertEquals(Visibility.PUBLIC_ONLY, v.getCreatorVisibility()); v = NO_OVERRIDES.withFieldVisibility(Visibility.ANY); assertEquals(Visibility.ANY, v.getFieldVisibility()); v = NO_OVERRIDES.withGetterVisibility(Visibility.NON_PRIVATE); assertEquals(Visibility.NON_PRIVATE, v.getGetterVisibility()); v = NO_OVERRIDES.withIsGetterVisibility(Visibility.PROTECTED_AND_PUBLIC); assertEquals(Visibility.PROTECTED_AND_PUBLIC, v.getIsGetterVisibility()); v = NO_OVERRIDES.withSetterVisibility(Visibility.PUBLIC_ONLY); assertEquals(Visibility.PUBLIC_ONLY, v.getSetterVisibility()); } }