|
1 |
| -package com.fasterxml.jackson.failing; |
| 1 | +package com.fasterxml.jackson.databind.objectid; |
2 | 2 |
|
3 | 3 | import java.util.*;
|
4 | 4 |
|
5 | 5 | import com.fasterxml.jackson.annotation.*;
|
6 | 6 | import com.fasterxml.jackson.core.type.TypeReference;
|
7 | 7 | import com.fasterxml.jackson.databind.*;
|
8 | 8 |
|
9 |
| -public class JsonIdentiyInfo1388Test extends BaseMapTest |
| 9 | +public class ObjectIdReordering1388Test extends BaseMapTest |
10 | 10 | {
|
11 | 11 | @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
|
12 | 12 | public static class NamedThing {
|
@@ -50,28 +50,33 @@ public void testDeserializationFinalClassJSOG() throws Exception
|
50 | 50 |
|
51 | 51 | final TypeReference<?> namedThingListType = new TypeReference<List<NamedThing>>() { };
|
52 | 52 |
|
53 |
| - final String jsog = mapper.writeValueAsString(Arrays.asList(thing, thing, thing)); |
54 | 53 | {
|
| 54 | + final String jsog = mapper.writeValueAsString(Arrays.asList(thing, thing, thing)); |
55 | 55 | final List<NamedThing> list = mapper.readValue(jsog, namedThingListType);
|
56 | 56 | _assertAllSame(list);
|
| 57 | + // this is the jsog representation of the list of 3 of the same item |
| 58 | + assertTrue(jsog.equals("[{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"},1,1]")); |
57 | 59 | }
|
58 | 60 |
|
59 |
| - // this is the jsog representation of the list of 3 of the same item |
60 |
| - assertTrue(jsog.equals("[{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"},1,1]")); |
61 |
| - |
62 | 61 | // now move it around it have forward references
|
63 |
| - final String forwardReferences = "[1,1,{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"}]"; |
64 | 62 | // this works
|
65 | 63 | {
|
66 |
| - final List<NamedThing> forward = mapper.readValue(forwardReferences, namedThingListType); |
| 64 | + final String json = "[1,1,{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"}]"; |
| 65 | + final List<NamedThing> forward = mapper.readValue(json, namedThingListType); |
| 66 | + _assertAllSame(forward); |
| 67 | + } |
| 68 | + |
| 69 | + // next, move @id to between properties |
| 70 | + { |
| 71 | + final String json = aposToQuotes("[{'id':'a59aa02c-fe3c-43f8-9b5a-5fe01878a818','@id':1,'name':'Hello'}, 1, 1]"); |
| 72 | + final List<NamedThing> forward = mapper.readValue(json, namedThingListType); |
67 | 73 | _assertAllSame(forward);
|
68 | 74 | }
|
69 | 75 |
|
70 |
| - // now move the @id to be not the first key in the object |
71 |
| - final String notFirstKey = "[1,1,{\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\",\"@id\":1}]"; |
72 |
| - // this fails |
| 76 | + // and last, move @id to be not the first key in the object |
73 | 77 | {
|
74 |
| - final List<NamedThing> forward = mapper.readValue(notFirstKey, namedThingListType); |
| 78 | + final String json = aposToQuotes("[{'id':'a59aa02c-fe3c-43f8-9b5a-5fe01878a818','name':'Hello','@id':1}, 1, 1]"); |
| 79 | + final List<NamedThing> forward = mapper.readValue(json, namedThingListType); |
75 | 80 | _assertAllSame(forward);
|
76 | 81 | }
|
77 | 82 | }
|
|
0 commit comments