Skip to content

Commit 42bf46c

Browse files
authored
Fix #326: add JsonTypeInfo.As.NOTHING (#327)
1 parent 0d36a27 commit 42bf46c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ NOTE: Jackson 3.x components rely on 2.x annotations; there are no separate
2525
#320: Add `radix` property to `@JsonFormat` annotation
2626
(contributed by @tiger9800)
2727
#324: Add `@JsonSerializeAs`
28+
#326: Add `JsonTypeInfo.As.NOTHING` value
2829
- Fix SBOM generation, publishing
2930

3031
2.20 (28-Aug-2025)

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public enum Id {
8080
/**
8181
* This means that no explicit type metadata is included, and typing is
8282
* purely done using contextual information possibly augmented with other
83-
* annotations.
83+
* annotations. Or, format-specific metadata mechanism is used.
84+
* Typically used with {@link As#NOTHING}.
8485
*/
8586
NONE(null),
8687

@@ -175,7 +176,7 @@ private Id(String defProp) {
175176

176177
/**
177178
* Definition of standard type inclusion mechanisms for type metadata.
178-
* Used for standard metadata types, except for {@link Id#NONE}.
179+
* Used for standard metadata types.
179180
* May or may not be used for custom types ({@link Id#CUSTOM}).
180181
*/
181182
public enum As {
@@ -240,7 +241,17 @@ public enum As {
240241
*
241242
* @since 2.3 but databind <b>only since 2.5</b>.
242243
*/
243-
EXISTING_PROPERTY
244+
EXISTING_PROPERTY,
245+
246+
/**
247+
* Pseudo-value used as marker for case where no in-data Type Id is included:
248+
* either because separate metadata (using format native mechanism) is used,
249+
* or inference mechanism is used or possibly no Type Id is used at all
250+
* (to match {@link Id#NONE} case).
251+
*
252+
* @since 2.21
253+
*/
254+
NOTHING
244255
;
245256
}
246257

@@ -376,9 +387,9 @@ public static class Value
376387
{
377388
private static final long serialVersionUID = 1L;
378389

379-
// should not really be needed usually but make sure defalts to `NONE`; other
390+
// should not really be needed usually but make sure defaults to `NONE`; other
380391
// values of less interest
381-
protected final static Value EMPTY = new Value(Id.NONE, As.PROPERTY, null, null, false, null);
392+
protected final static Value EMPTY = new Value(Id.NONE, As.NOTHING, null, null, false, null);
382393

383394
protected final Id _idType;
384395
protected final As _inclusionType;
@@ -493,7 +504,8 @@ public Class<JsonTypeInfo> valueFor() {
493504
*/
494505
public static boolean isEnabled(JsonTypeInfo.Value v) {
495506
return (v != null) &&
496-
(v._idType != null) && (v._idType != Id.NONE);
507+
(v._idType != null) && (v._idType != Id.NONE)
508+
&& (v._inclusionType != As.NOTHING);
497509
}
498510

499511
/*

0 commit comments

Comments
 (0)