Skip to content

Commit f2f611e

Browse files
committed
Fix #928
1 parent d485ea7 commit f2f611e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Project: jackson-databind
1313
#913: ObjectMapper.copy does not preserve MappingJsonFactory features
1414
(reported, fixed by Daniel W)
1515
#922: ObjectMapper.copy() does not preserve _registeredModuleTypes
16+
#928: Problem deserializing External Type Id if type id comes before POJO
1617

1718
2.6.1 (09-Aug-2015)
1819

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,9 @@ protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p, D
789789
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
790790
if (creatorProp != null) {
791791
// first: let's check to see if this might be part of value with external type id:
792-
if (ext.handlePropertyValue(p, ctxt, propName, buffer)) {
792+
// 11-Sep-2015, tatu: Important; do NOT pass buffer as last arg, but null,
793+
// since it is not the bean
794+
if (ext.handlePropertyValue(p, ctxt, propName, null)) {
793795
;
794796
} else {
795797
// Last creator property to set?

src/test/java/com/fasterxml/jackson/databind/jsontype/TestExternalId.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,12 @@ public Issue222BeanB() { }
238238

239239
// [databind#928]
240240
static class Envelope928 {
241-
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.EXTERNAL_PROPERTY, property="class")
242-
Object payload;
241+
Object _payload;
243242

244-
public Envelope928(@JsonProperty("payload") Object payload) {
245-
this.payload = payload;
243+
public Envelope928(@JsonProperty("payload")
244+
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.EXTERNAL_PROPERTY, property="class")
245+
Object payload) {
246+
_payload = payload;
246247
}
247248
}
248249

@@ -487,12 +488,12 @@ public void testInverseExternalId928() throws Exception
487488
final String successCase = "{\"payload\":{\"something\":\"test\"},\"class\":\""+CLASS+"\"}";
488489
Envelope928 envelope1 = mapper.readValue(successCase, Envelope928.class);
489490
assertNotNull(envelope1);
490-
assertEquals(Payload928.class, envelope1.payload.getClass());
491+
assertEquals(Payload928.class, envelope1._payload.getClass());
491492

492493
// and then re-ordered case that was problematic
493494
final String failCase = "{\"class\":\""+CLASS+"\",\"payload\":{\"something\":\"test\"}}";
494495
Envelope928 envelope2 = mapper.readValue(failCase, Envelope928.class);
495496
assertNotNull(envelope2);
496-
assertEquals(Payload928.class, envelope2.payload.getClass());
497+
assertEquals(Payload928.class, envelope2._payload.getClass());
497498
}
498499
}

0 commit comments

Comments
 (0)