|
1 | 1 | package com.fasterxml.jackson.databind.format;
|
2 | 2 |
|
| 3 | +import java.util.Collection; |
| 4 | +import java.util.HashMap; |
3 | 5 | import java.util.LinkedHashMap;
|
| 6 | +import java.util.Map; |
| 7 | +import java.util.Set; |
4 | 8 |
|
5 | 9 | import com.fasterxml.jackson.annotation.JsonFormat;
|
| 10 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
6 | 11 | import com.fasterxml.jackson.annotation.JsonInclude;
|
7 | 12 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
8 | 13 | import com.fasterxml.jackson.databind.*;
|
@@ -54,6 +59,84 @@ public Bean476Override(int value) {
|
54 | 59 | }
|
55 | 60 | }
|
56 | 61 |
|
| 62 | + // from [databind#1540] |
| 63 | + @JsonFormat(shape = JsonFormat.Shape.OBJECT) |
| 64 | + @JsonPropertyOrder({ "property", "map" }) |
| 65 | + static class Map1540Implementation implements Map<Integer, Integer> { |
| 66 | + public int property; |
| 67 | + public Map<Integer, Integer> map = new HashMap<>(); |
| 68 | + |
| 69 | + public Map<Integer, Integer> getMap() { |
| 70 | + return map; |
| 71 | + } |
| 72 | + |
| 73 | + public void setMap(Map<Integer, Integer> map) { |
| 74 | + this.map = map; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public Integer put(Integer key, Integer value) { |
| 79 | + return map.put(key, value); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public int size() { |
| 84 | + return map.size(); |
| 85 | + } |
| 86 | + |
| 87 | + @JsonIgnore |
| 88 | + @Override |
| 89 | + public boolean isEmpty() { |
| 90 | + return map.isEmpty(); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public boolean containsKey(Object key) { |
| 95 | + return map.containsKey(key); |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public boolean containsValue(Object value) { |
| 100 | + return map.containsValue(value); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public Integer get(Object key) { |
| 105 | + return map.get(key); |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public Integer remove(Object key) { |
| 110 | + return map.remove(key); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public void putAll(Map<? extends Integer, ? extends Integer> m) { |
| 115 | + map.putAll(m); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public void clear() { |
| 120 | + map.clear(); |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + public Set<Integer> keySet() { |
| 125 | + return map.keySet(); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public Collection<Integer> values() { |
| 130 | + return map.values(); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public Set<java.util.Map.Entry<Integer, Integer>> entrySet() { |
| 135 | + return map.entrySet(); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + |
57 | 140 | /*
|
58 | 141 | /**********************************************************
|
59 | 142 | /* Test methods, serialization
|
@@ -94,6 +177,23 @@ public void testSerializeNaturalViaOverride() throws Exception
|
94 | 177 | /**********************************************************
|
95 | 178 | */
|
96 | 179 |
|
| 180 | + // [databind#1540] |
| 181 | + public void testRoundTrip() throws Exception |
| 182 | + { |
| 183 | + Map1540Implementation input = new Map1540Implementation(); |
| 184 | + input.property = 55; |
| 185 | + input.put(12, 45); |
| 186 | + input.put(6, 88); |
| 187 | + |
| 188 | + String json = MAPPER.writeValueAsString(input); |
| 189 | + |
| 190 | + assertEquals(aposToQuotes("{'property':55,'map':{'6':88,'12':45}}"), json); |
| 191 | + |
| 192 | + Map1540Implementation result = MAPPER.readValue(json, Map1540Implementation.class); |
| 193 | + assertEquals(result.property, input.property); |
| 194 | + assertEquals(input.getMap(), input.getMap()); |
| 195 | + } |
| 196 | + |
97 | 197 | // [databind#1554]
|
98 | 198 | public void testDeserializeAsPOJOViaClass() throws Exception
|
99 | 199 | {
|
|
0 commit comments