Skip to content

Commit 98f2f31

Browse files
committed
Fixed #108
1 parent c12f874 commit 98f2f31

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ NOTE: Annotations module will never contain changes in patch versions,
1616
#103: Add `JsonInclude.Include.CUSTOM`, properties for specifying filter(s) to use
1717
#104: Add new properties in `@JsonSetter`: `merge`, `null`/`contentNulls`
1818
#105: Add `@JsonFormat.lenient` to allow configuring lenience of date/time deserializers
19+
#108: Allow `@JsonValue` on fields
1920
- Allow use of `@JsonView` on classes, to specify Default View to use on non-annotated
2021
properties.
2122

src/main/java/com/fasterxml/jackson/annotation/JsonValue.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Marker annotation similar to
10-
* {@link javax.xml.bind.annotation.XmlValue}
11-
* that indicates that results of the annotated "getter" method
12-
* (which means signature must be that of getters; non-void return
13-
* type, no args) is to be used as the single value to serialize
14-
* for the instance. Usually value will be of a simple scalar type
9+
* Marker annotation
10+
* that indicates that the value of annotated accessor (either field
11+
* or "getter" method [a method with non-void return type, no args])
12+
* is to be used as the single value to serialize for the instance,
13+
* instead of the usual method of collecting properties of value.
14+
* Usually value will be of a simple scalar type
1515
* (String or Number), but it can be any serializable type (Collection,
1616
* Map or Bean).
1717
*<p>
18-
* At most one method of a <code>Class</code> can be annotated with this annotation;
18+
* At most one accessor of a <code>Class</code> can be annotated with this annotation;
1919
* if more than one is found, an exception may be thrown.
20-
* Also, if method signature is not compatible with Getters, an exception
21-
* may be thrown (whether exception is thrown or not is an implementation detail (due
22-
* to filtering during introspection, some annotations may be skipped)
23-
* and applications should not rely on specific behavior).
20+
* Also, if method signature of annotated method is not compatible with Getters,
21+
* an exception may be thrown (whether exception is thrown or not is an
22+
* implementation detail (due to filtering during introspection, some annotations
23+
* may be skipped) and applications should not rely on specific behavior).
2424
*<p>
2525
* A typical usage is that of annotating <code>toString()</code>
2626
* method so that returned String value is used as the JSON serialization;
@@ -39,7 +39,9 @@
3939
*
4040
* @see JsonCreator
4141
*/
42-
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
42+
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD,
43+
ElementType.FIELD // since 2.9
44+
})
4345
@Retention(RetentionPolicy.RUNTIME)
4446
@JacksonAnnotation
4547
public @interface JsonValue

0 commit comments

Comments
 (0)