Skip to content

Commit 6da4e47

Browse files
committed
Backport JsonFormat changes from now-removed 3.0
1 parent 1c405ac commit 6da4e47

File tree

1 file changed

+64
-51
lines changed

1 file changed

+64
-51
lines changed

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

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.Locale;
55
import java.util.TimeZone;
66

7+
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
8+
79
/**
810
* General-purpose annotation used for configuring details of how
911
* values of properties are to be serialized and deserialized.
@@ -17,7 +19,7 @@
1719
* or String (such as ISO-8601 compatible time value) -- as well as configuring
1820
* exact details with {@link #pattern} property.
1921
*<p>
20-
* As of Jackson 2.18, known special handling includes:
22+
* As of Jackson 2.19, known special handling includes:
2123
*<ul>
2224
* <li>{@link java.util.Date} or {@link java.util.Calendar}: Shape can be {@link Shape#STRING} or {@link Shape#NUMBER};
2325
* pattern may contain {@link java.text.SimpleDateFormat}-compatible pattern definition.
@@ -152,40 +154,20 @@
152154
*/
153155
public enum Shape
154156
{
157+
// // // Concrete physical shapes, scalars
155158
/**
156-
* Marker enum value that indicates "whatever" choice, meaning that annotation
157-
* does NOT specify shape to use.
158-
* Note that this is different from {@link Shape#NATURAL}, which
159-
* specifically instructs use of the "natural" shape for datatype.
160-
*/
161-
ANY,
162-
163-
/**
164-
* Marker enum value that indicates the "default" choice for given datatype;
165-
* for example, JSON String for {@link java.lang.String}, or JSON Number
166-
* for Java numbers.
167-
* Note that this is different from {@link Shape#ANY} in that this is actual
168-
* explicit choice that overrides possible default settings.
159+
* Value that indicates that Binary type (native, if format supports it;
160+
* encoding using Base64 if only textual types supported) should be used.
169161
*
170-
* @since 2.8
171-
*/
172-
NATURAL,
173-
174-
/**
175-
* Value that indicates shape should not be structural (that is, not
176-
* {@link #ARRAY} or {@link #OBJECT}), but can be any other shape.
177-
*/
178-
SCALAR,
179-
180-
/**
181-
* Value that indicates that (JSON) Array type should be used.
162+
* @since 2.10
182163
*/
183-
ARRAY,
164+
BINARY,
184165

185166
/**
186-
* Value that indicates that (JSON) Object type should be used.
167+
* Value that indicates that (JSON) boolean type
168+
* (true, false) should be used.
187169
*/
188-
OBJECT,
170+
BOOLEAN,
189171

190172
/**
191173
* Value that indicates that a numeric (JSON) type should be used
@@ -211,26 +193,71 @@ public enum Shape
211193
STRING,
212194

213195
/**
214-
* Value that indicates that (JSON) boolean type
215-
* (true, false) should be used.
196+
* Value that indicates shape should not be structural (that is, not
197+
* {@link #ARRAY} or {@link #OBJECT}), but can be any other shape.
216198
*/
217-
BOOLEAN,
199+
SCALAR,
200+
201+
// // // Concrete physical shapes, structured
218202

219203
/**
220-
* Value that indicates that Binary type (native, if format supports it;
221-
* encoding using Base64 if only textual types supported) should be used.
204+
* Value that indicates that (JSON) Array type should be used.
205+
*/
206+
ARRAY,
207+
208+
/**
209+
* Value that indicates that (JSON) Object type should be used.
210+
*/
211+
OBJECT,
212+
213+
// // // Additional logical meta-types
214+
215+
/**
216+
* Marker enum value that indicates "whatever" choice, meaning that annotation
217+
* does NOT specify shape to use.
218+
* Note that this is different from {@link Shape#NATURAL}, which
219+
* specifically instructs use of the "natural" shape for datatype.
220+
*/
221+
ANY,
222+
223+
/**
224+
* Marker enum value that indicates the "default" choice for given datatype;
225+
* for example, JSON String for {@link java.lang.String}, or JSON Number
226+
* for Java numbers.
227+
* Note that this is different from {@link Shape#ANY} in that this is actual
228+
* explicit choice that overrides possible default settings.
222229
*
223-
* @since 2.10
230+
* @since 2.8
231+
*/
232+
NATURAL,
233+
234+
/**
235+
* Marker enum value that indicates not only shape of {@link #OBJECT} but further
236+
* handling as POJO, where applicable. Mostly makes difference at Java Object level
237+
* when distinguishing handling between {@link java.util.Map} and POJO types.
238+
*
239+
* @since 2.20
224240
*/
225-
BINARY
241+
POJO,
242+
226243
;
227244

228245
public boolean isNumeric() {
229246
return (this == NUMBER) || (this == NUMBER_INT) || (this == NUMBER_FLOAT);
230247
}
231248

249+
/** @since 2.20 */
250+
public static boolean isNumeric(Shape shapeOrNull) {
251+
return (shapeOrNull != null) && shapeOrNull.isNumeric();
252+
}
253+
232254
public boolean isStructured() {
233-
return (this == OBJECT) || (this == ARRAY);
255+
return (this == OBJECT) || (this == ARRAY) || (this == POJO);
256+
}
257+
258+
/** @since 2.20 */
259+
public static boolean isStructured(Shape shapeOrNull) {
260+
return (shapeOrNull != null) && shapeOrNull.isStructured();
234261
}
235262
}
236263

@@ -541,20 +568,6 @@ public Value(String p, Shape sh, Locale l, String tzStr, TimeZone tz, Features f
541568
_lenient = lenient;
542569
}
543570

544-
@Deprecated // since 2.9
545-
public Value(String p, Shape sh, Locale l, String tzStr, TimeZone tz, Features f) {
546-
this(p, sh, l, tzStr, tz, f, null);
547-
}
548-
549-
@Deprecated // since 2.9
550-
public Value(String p, Shape sh, String localeStr, String tzStr, Features f) {
551-
this(p, sh, localeStr, tzStr, f, null);
552-
}
553-
@Deprecated // since 2.9
554-
public Value(String p, Shape sh, Locale l, TimeZone tz, Features f) {
555-
this(p, sh, l, tz, f, null);
556-
}
557-
558571
/**
559572
* @since 2.7
560573
*/

0 commit comments

Comments
 (0)