|
1 | 1 | package com.fasterxml.jackson.databind.struct; |
2 | 2 |
|
3 | | -import java.io.IOException; |
4 | | - |
5 | 3 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; |
6 | 4 | import com.fasterxml.jackson.annotation.JsonProperty; |
7 | 5 | import com.fasterxml.jackson.annotation.JsonTypeInfo; |
| 6 | +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; |
| 7 | +import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; |
8 | 8 | import com.fasterxml.jackson.annotation.ObjectIdGenerator; |
9 | 9 | import com.fasterxml.jackson.core.JsonParser; |
| 10 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 11 | +import com.fasterxml.jackson.databind.DeserializationContext; |
| 12 | +import com.fasterxml.jackson.databind.JsonDeserializer; |
| 13 | +import com.fasterxml.jackson.databind.JsonNode; |
| 14 | +import com.fasterxml.jackson.databind.ObjectMapper; |
10 | 15 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
11 | | -import com.fasterxml.jackson.databind.*; |
| 16 | +import java.io.IOException; |
12 | 17 |
|
13 | 18 | /** |
14 | 19 | * Unit test(s) for [databind#622], supporting non-scalar-Object-ids, |
@@ -187,4 +192,48 @@ public void testPolymorphicRoundTrip() throws Exception |
187 | 192 | assertEquals(123, jsog.foo); |
188 | 193 | assertSame(jsog, jsog.next); |
189 | 194 | } |
| 195 | + |
| 196 | + // |
| 197 | + // For databind issue #669 |
| 198 | + // |
| 199 | + |
| 200 | + @JsonIdentityInfo(generator=JSOGGenerator.class) |
| 201 | + @JsonTypeInfo(use=Id.CLASS, include= As.PROPERTY, property="@class") |
| 202 | + public static class Inner { |
| 203 | + public String bar; |
| 204 | + |
| 205 | + public Inner() {} |
| 206 | + public Inner(String bar) { this.bar = bar; } |
| 207 | + } |
| 208 | + |
| 209 | + public static class SubInner extends Inner { |
| 210 | + public String extra; |
| 211 | + |
| 212 | + public SubInner() {} |
| 213 | + public SubInner(String bar, String extra) { |
| 214 | + super(bar); |
| 215 | + this.extra = extra; |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + @JsonIdentityInfo(generator=JSOGGenerator.class) |
| 220 | + public static class Outer { |
| 221 | + public String foo; |
| 222 | + public Inner inner1; |
| 223 | + public Inner inner2; |
| 224 | + } |
| 225 | + |
| 226 | + // polymorphic alternative for [#669] |
| 227 | + public void testAlterativePolymorphicRoundTrip() throws Exception |
| 228 | + { |
| 229 | + Outer outer = new Outer(); |
| 230 | + outer.foo = "foo"; |
| 231 | + outer.inner1 = outer.inner2 = new SubInner("bar", "extra"); |
| 232 | + |
| 233 | + String jsog = MAPPER.writeValueAsString(outer); |
| 234 | + |
| 235 | + Outer back = MAPPER.readValue(jsog, Outer.class); |
| 236 | + |
| 237 | + assertSame(back.inner1, back.inner2); |
| 238 | + } |
190 | 239 | } |
0 commit comments