Skip to content

Commit ef6564c

Browse files
committed
Fix #3373
1 parent 6aef72b commit ef6564c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Project: jackson-databind
66

77
2.14.0 (not yet released)
88

9-
No changes since 2.13
9+
#3373: Change `TypeSerializerBase` to skip `generator.writeTypePrefix()`
10+
for `null` typeId
1011

1112
2.13.2 (not yet released)
1213

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeSerializerBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@ public WritableTypeId writeTypePrefix(JsonGenerator g,
4343
WritableTypeId idMetadata) throws IOException
4444
{
4545
_generateTypeId(idMetadata);
46+
// 16-Jan-2022, tatu: As per [databind#3373], skip for null typeId.
47+
// And return "null" so that matching "writeTypeSuffix" call should
48+
// be avoided as well.
49+
if (idMetadata.id == null) {
50+
return null;
51+
}
4652
return g.writeTypePrefix(idMetadata);
4753
}
4854

4955
@Override
5056
public WritableTypeId writeTypeSuffix(JsonGenerator g,
5157
WritableTypeId idMetadata) throws IOException
5258
{
59+
// 16-Jan-2022, tatu: As per [databind#3373], skip for null:
60+
if (idMetadata == null) {
61+
return null;
62+
}
5363
return g.writeTypeSuffix(idMetadata);
5464
}
5565

0 commit comments

Comments
 (0)