Skip to content

Commit d485ea7

Browse files
committed
Add test for #928
1 parent b9df8c9 commit d485ea7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ public Issue222BeanB() { }
236236
public Issue222BeanB(int value) { x = value; }
237237
}
238238

239+
// [databind#928]
240+
static class Envelope928 {
241+
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.EXTERNAL_PROPERTY, property="class")
242+
Object payload;
243+
244+
public Envelope928(@JsonProperty("payload") Object payload) {
245+
this.payload = payload;
246+
}
247+
}
248+
249+
static class Payload928 {
250+
public String something;
251+
}
252+
239253
/*
240254
/**********************************************************
241255
/* Unit tests, serialization
@@ -462,4 +476,23 @@ public void testExternalTypeWithProp222() throws Exception
462476
String json = mapper.writeValueAsString(input);
463477
assertEquals("{\"value\":{\"x\":13},\"type\":\"foo\"}", json);
464478
}
479+
480+
// [databind#928]
481+
public void testInverseExternalId928() throws Exception
482+
{
483+
final String CLASS = Payload928.class.getName();
484+
485+
ObjectMapper mapper = new ObjectMapper();
486+
487+
final String successCase = "{\"payload\":{\"something\":\"test\"},\"class\":\""+CLASS+"\"}";
488+
Envelope928 envelope1 = mapper.readValue(successCase, Envelope928.class);
489+
assertNotNull(envelope1);
490+
assertEquals(Payload928.class, envelope1.payload.getClass());
491+
492+
// and then re-ordered case that was problematic
493+
final String failCase = "{\"class\":\""+CLASS+"\",\"payload\":{\"something\":\"test\"}}";
494+
Envelope928 envelope2 = mapper.readValue(failCase, Envelope928.class);
495+
assertNotNull(envelope2);
496+
assertEquals(Payload928.class, envelope2.payload.getClass());
497+
}
465498
}

0 commit comments

Comments
 (0)