diff --git a/release-notes/VERSION b/release-notes/VERSION index 011ba38e..b12d6cec 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -16,6 +16,7 @@ NOTE: Annotations module will never contain changes in patch versions, #103: Add `JsonInclude.Include.CUSTOM`, properties for specifying filter(s) to use #104: Add new properties in `@JsonSetter`: `merge`, `null`/`contentNulls` #105: Add `@JsonFormat.lenient` to allow configuring lenience of date/time deserializers +#108: Allow `@JsonValue` on fields - Allow use of `@JsonView` on classes, to specify Default View to use on non-annotated properties. diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonValue.java b/src/main/java/com/fasterxml/jackson/annotation/JsonValue.java index ee055263..d78231bc 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonValue.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonValue.java @@ -6,21 +6,21 @@ import java.lang.annotation.Target; /** - * Marker annotation similar to - * {@link javax.xml.bind.annotation.XmlValue} - * that indicates that results of the annotated "getter" method - * (which means signature must be that of getters; non-void return - * type, no args) is to be used as the single value to serialize - * for the instance. Usually value will be of a simple scalar type + * 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 method of a Class
can be annotated with this annotation;
+ * 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 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).
+ * 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;
@@ -39,7 +39,9 @@
*
* @see JsonCreator
*/
-@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
+@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD,
+ ElementType.FIELD // since 2.9
+})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface JsonValue