Skip to content

Commit f678140

Browse files
committed
Fix #3914
1 parent b8a22db commit f678140

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Project: jackson-databind
1111
#3913: Issue with deserialization when there are unexpected properties (due
1212
to null `StreamReadConstraints`)
1313
(reported by @sbertault)
14+
#3914: Fix TypeId serialization for `JsonTypeInfo.Id.DEDUCTION`, native type ids
1415

1516
2.15.0 (23-Apr-2023)
1617

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
66
import com.fasterxml.jackson.core.JsonGenerator;
7+
import com.fasterxml.jackson.core.JsonToken;
78
import com.fasterxml.jackson.core.type.WritableTypeId;
89
import com.fasterxml.jackson.databind.BeanProperty;
910

@@ -39,9 +40,19 @@ public WritableTypeId writeTypePrefix(JsonGenerator g,
3940
// write surrounding Object or Array start/end markers. But
4041
// we are not to generate type id to write (compared to base class)
4142

42-
if (idMetadata.valueShape.isStructStart()
43-
// also: do not try to write native type id
44-
&& !g.canWriteTypeId()) {
43+
if (idMetadata.valueShape.isStructStart()) {
44+
// 03-May-2023, tatu: [databind#3914]: should not write Native Type Id;
45+
// but may need to write the value start marker
46+
if (g.canWriteTypeId()) {
47+
idMetadata.wrapperWritten = false;
48+
if (idMetadata.valueShape == JsonToken.START_OBJECT) {
49+
g.writeStartObject(idMetadata.forValue);
50+
} else if (idMetadata.valueShape == JsonToken.START_ARRAY) {
51+
g.writeStartArray(idMetadata.forValue);
52+
}
53+
return idMetadata;
54+
}
55+
// But for non-wrapper types can just use the default handling
4556
return g.writeTypePrefix(idMetadata);
4657
}
4758
return null;

0 commit comments

Comments
 (0)