@@ -99,36 +99,12 @@ public EmptyEntryWrapper(String key, String value) {
99
99
100
100
/*
101
101
/**********************************************************
102
- /* Test methods
102
+ /* Test methods, basic
103
103
/**********************************************************
104
104
*/
105
105
106
106
private final ObjectMapper MAPPER = newObjectMapper ();
107
107
108
- public void testAsNaturalRoundtrip () throws Exception
109
- {
110
- BeanWithMapEntry input = new BeanWithMapEntry ("foo" ,"bar" );
111
- String json = MAPPER .writeValueAsString (input );
112
- assertEquals (aposToQuotes ("{'entry':{'foo':'bar'}}" ), json );
113
- BeanWithMapEntry result = MAPPER .readValue (json , BeanWithMapEntry .class );
114
- assertEquals ("foo" , result .entry .getKey ());
115
- assertEquals ("bar" , result .entry .getValue ());
116
- }
117
- // should work via class annotation
118
- public void testAsObjectRoundtrip () throws Exception
119
- {
120
- MapEntryAsObject input = new MapEntryAsObject ("foo" ,"bar" );
121
- String json = MAPPER .writeValueAsString (input );
122
- assertEquals (aposToQuotes ("{'key':'foo','value':'bar'}" ), json );
123
-
124
- // 16-Oct-2016, tatu: Happens to work by default because it's NOT basic
125
- // `Map.Entry` but subtype.
126
-
127
- MapEntryAsObject result = MAPPER .readValue (json , MapEntryAsObject .class );
128
- assertEquals ("foo" , result .getKey ());
129
- assertEquals ("bar" , result .getValue ());
130
- }
131
-
132
108
public void testInclusion () throws Exception
133
109
{
134
110
assertEquals (aposToQuotes ("{'entry':{'a':'b'}}" ),
@@ -159,4 +135,45 @@ public void testInclusionWithReference() throws Exception
159
135
assertEquals (aposToQuotes ("{}" ),
160
136
MAPPER .writeValueAsString (new EntryWithNonAbsentWrapper ("a" , null )));
161
137
}
138
+
139
+ /*
140
+ /**********************************************************
141
+ /* Test methods, as-Object (Shape)
142
+ /**********************************************************
143
+ */
144
+
145
+ public void testAsNaturalRoundtrip () throws Exception
146
+ {
147
+ BeanWithMapEntry input = new BeanWithMapEntry ("foo" ,"bar" );
148
+ String json = MAPPER .writeValueAsString (input );
149
+ assertEquals (aposToQuotes ("{'entry':{'foo':'bar'}}" ), json );
150
+ BeanWithMapEntry result = MAPPER .readValue (json , BeanWithMapEntry .class );
151
+ assertEquals ("foo" , result .entry .getKey ());
152
+ assertEquals ("bar" , result .entry .getValue ());
153
+ }
154
+ // should work via class annotation
155
+ public void testAsObjectRoundtrip () throws Exception
156
+ {
157
+ MapEntryAsObject input = new MapEntryAsObject ("foo" ,"bar" );
158
+ String json = MAPPER .writeValueAsString (input );
159
+ assertEquals (aposToQuotes ("{'key':'foo','value':'bar'}" ), json );
160
+
161
+ // 16-Oct-2016, tatu: Happens to work by default because it's NOT basic
162
+ // `Map.Entry` but subtype.
163
+
164
+ MapEntryAsObject result = MAPPER .readValue (json , MapEntryAsObject .class );
165
+ assertEquals ("foo" , result .getKey ());
166
+ assertEquals ("bar" , result .getValue ());
167
+ }
168
+
169
+ // [databind#1895]
170
+ public void testDefaultShapeOverride () throws Exception
171
+ {
172
+ ObjectMapper mapper = new ObjectMapper ();
173
+ mapper .configOverride (Map .Entry .class )
174
+ .setFormat (JsonFormat .Value .forShape (JsonFormat .Shape .OBJECT ));
175
+ Map .Entry <String ,String > input = new BeanWithMapEntry ("foo" , "bar" ).entry ;
176
+ assertEquals (aposToQuotes ("{'key':'foo','value':'bar'}" ),
177
+ mapper .writeValueAsString (input ));
178
+ }
162
179
}
0 commit comments