Skip to content

Commit 7500337

Browse files
committed
Merge branch '2.19'
2 parents 414fe8a + 753e6c0 commit 7500337

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ NOTE: Annotations module will never contain changes in patch versions,
1616
#280: Minor change to `module-info.java`: use "open module"
1717
#281: [gradle-module-metadata-maven-plugin] update to version 1.0
1818
(contributed by @jjohannes)
19+
#284: Add `OptBoolean` valued `@JsonProperty.isRequired` to
20+
(eventually) replace `@JsonProperty.required`
1921

2022
2.18.0 (26-Sep-2024)
2123

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
/**
88
* General-purpose annotation used for configuring details of how
9-
* values of properties are to be serialized.
9+
* values of properties are to be serialized and deserialized.
1010
* Unlike most other Jackson annotations, annotation does not
11-
* have specific universal interpretation: instead, effect depends on datatype
11+
* have specific universal interpretation: instead, effects depend on datatype
1212
* of property being annotated (or more specifically, deserializer
1313
* and serializer being used).
1414
*<p>
@@ -19,7 +19,7 @@
1919
*<p>
2020
* As of Jackson 3.0, known special handling includes:
2121
*<ul>
22-
* <li>{@link java.util.Date} or {@link java.util.Calendar} : Shape can be {@link Shape#STRING} or {@link Shape#NUMBER};
22+
* <li>{@link java.util.Date} or {@link java.util.Calendar}: Shape can be {@link Shape#STRING} or {@link Shape#NUMBER};
2323
* pattern may contain {@link java.text.SimpleDateFormat}-compatible pattern definition.
2424
* </li>
2525
* <li>{@code java.time.*}: Types in the {@code java.time} package can use

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* since it would associate same annotation for all fields, leading to name
3131
* collision.
3232
*<p>
33-
* Starting with Jackson 2.6 this annotation may also be
33+
* This annotation may also be
3434
* used to change serialization of {@code Enum} like so:
3535
*<pre>
3636
public enum MyEnum {
@@ -39,13 +39,12 @@ public enum MyEnum {
3939
}
4040
</pre>
4141
* as an alternative to using {@link JsonValue} annotation.
42-
*<br />
42+
*<br>
4343
* NOTE: for {@code Enum}s, empty String is a valid value (and
4444
* missing {@code value} is taken as empty String), unlike for regular
4545
* properties, and does NOT mean "use default Enum name".
46-
* (handling fixed in Jackson 2.19)
4746
*<p>
48-
* Starting with Jackson 2.12 it is also possible to specify {@code namespace}
47+
* It is also possible to specify {@code namespace}
4948
* of property: this property is only used by certain format backends (most
5049
* notably XML).
5150
*/
@@ -82,21 +81,33 @@ public enum MyEnum {
8281
* Optional namespace to use with data formats that support such
8382
* concept (specifically XML); if so, used with {@link #value} to
8483
* construct fully-qualified name.
85-
*
86-
* @since 2.12
8784
*/
8885
String namespace() default "";
8986

9087
/**
91-
* Property that indicates whether a value (which may be explicit
92-
* null) is expected for property during deserialization or not.
93-
* If expected, <code>BeanDeserialized</code> should indicate
88+
* Property similar to {@link #isRequired}, but one that only
89+
* allows two values ({@code true} and {@code false}), defaulting
90+
* to {@code false}.
91+
*
92+
* @deprecated Since 3.0 use {@link #isRequired} instead
93+
*/
94+
@Deprecated
95+
boolean required() default false;
96+
97+
/**
98+
* Property that MAY indicate whether a value (which may be explicit
99+
* null) is required for a property during deserialization or not.
100+
* If required ({code OptBoolean.TRUE}), {@code Deserializer} should indicate
94101
* this as a validity problem (usually by throwing an exception,
95102
* but this may be sent via problem handlers that can try to
96-
* rectify the problem, for example, by supplying a default
97-
* value).
103+
* rectify the problem, for example, by supplying a default value) if no
104+
* value is present in incoming content. If not required ({code OptBoolean.FALSE}),
105+
* no checking is to be done.
106+
* If not specified ({code OptBoolean.DEFAULT}) checking depends on higher
107+
* level settings (some modules may specify default "required-ness" for certain
108+
* kinds of properties).
98109
*<p>
99-
* Note that as of 2.6, this property is only used for Creator
110+
* Note that as of 3.0, this property is only used for Creator
100111
* Properties, to ensure existence of property value in JSON:
101112
* for other properties (ones injected using a setter or mutable
102113
* field), no validation is performed. Support for those cases
@@ -112,9 +123,13 @@ public enum MyEnum {
112123
* this property should be set to {@code false}. This is important because
113124
* validation of {@code required} properties occurs before the application of
114125
* secondary sources.
126+
*<p>
127+
* Default value ({@link OptBoolean#DEFAULT}) means that "required-ness"
128+
* is not specified by this annotation -- it is up to more general settings
129+
* (per-class, global) to determine whether the property is required or not.
115130
*/
116-
boolean required() default false;
117-
131+
OptBoolean isRequired() default OptBoolean.DEFAULT;
132+
118133
/**
119134
* Property that indicates numerical index of this property (relative
120135
* to other properties specified for the Object). This index

0 commit comments

Comments
 (0)