From f2f611e701c63c8e98e59f315641bd2bf2921aea Mon Sep 17 00:00:00 2001 From: Cowtowncoder Date: Fri, 11 Sep 2015 17:29:17 -0700 Subject: [PATCH] Fix #928 --- release-notes/VERSION | 1 + .../jackson/databind/deser/BeanDeserializer.java | 4 +++- .../jackson/databind/jsontype/TestExternalId.java | 13 +++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/release-notes/VERSION b/release-notes/VERSION index cf5a485500..47b42c9ace 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -13,6 +13,7 @@ Project: jackson-databind #913: ObjectMapper.copy does not preserve MappingJsonFactory features (reported, fixed by Daniel W) #922: ObjectMapper.copy() does not preserve _registeredModuleTypes +#928: Problem deserializing External Type Id if type id comes before POJO 2.6.1 (09-Aug-2015) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java index d0b6d7e95f..23d989e83d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java @@ -789,7 +789,9 @@ protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p, D SettableBeanProperty creatorProp = creator.findCreatorProperty(propName); if (creatorProp != null) { // first: let's check to see if this might be part of value with external type id: - if (ext.handlePropertyValue(p, ctxt, propName, buffer)) { + // 11-Sep-2015, tatu: Important; do NOT pass buffer as last arg, but null, + // since it is not the bean + if (ext.handlePropertyValue(p, ctxt, propName, null)) { ; } else { // Last creator property to set? diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestExternalId.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestExternalId.java index c84824f821..509ded50ef 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/TestExternalId.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/TestExternalId.java @@ -238,11 +238,12 @@ public Issue222BeanB() { } // [databind#928] static class Envelope928 { - @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.EXTERNAL_PROPERTY, property="class") - Object payload; + Object _payload; - public Envelope928(@JsonProperty("payload") Object payload) { - this.payload = payload; + public Envelope928(@JsonProperty("payload") + @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.EXTERNAL_PROPERTY, property="class") + Object payload) { + _payload = payload; } } @@ -487,12 +488,12 @@ public void testInverseExternalId928() throws Exception final String successCase = "{\"payload\":{\"something\":\"test\"},\"class\":\""+CLASS+"\"}"; Envelope928 envelope1 = mapper.readValue(successCase, Envelope928.class); assertNotNull(envelope1); - assertEquals(Payload928.class, envelope1.payload.getClass()); + assertEquals(Payload928.class, envelope1._payload.getClass()); // and then re-ordered case that was problematic final String failCase = "{\"class\":\""+CLASS+"\",\"payload\":{\"something\":\"test\"}}"; Envelope928 envelope2 = mapper.readValue(failCase, Envelope928.class); assertNotNull(envelope2); - assertEquals(Payload928.class, envelope2.payload.getClass()); + assertEquals(Payload928.class, envelope2._payload.getClass()); } }