Skip to content
This repository was archived by the owner on Nov 5, 2019. It is now read-only.

Commit c731053

Browse files
committed
Add a (failing) test for #60
1 parent 565f8b4 commit c731053

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

src/test/java/com/fasterxml/jackson/module/afterburner/deser/TestSimpleDeserialize.java

+49-36
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.fasterxml.jackson.module.afterburner.deser;
22

3+
import java.util.List;
4+
35
import com.fasterxml.jackson.annotation.JsonProperty;
46
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
5-
67
import com.fasterxml.jackson.databind.ObjectMapper;
7-
88
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;
99

1010
public class TestSimpleDeserialize extends AfterburnerTestBase
@@ -138,21 +138,26 @@ public BigBeanWithNonVoidPropertySetter setStringField(String username) {
138138
public String getBogus5() { return ""; }
139139
}
140140

141+
// for [module-afterburner#60]
142+
static class Issue60Pojo {
143+
public List<Object> foos;
144+
}
145+
141146
/*
142147
/**********************************************************************
143148
/* Test methods, method access
144149
/**********************************************************************
145150
*/
146151

152+
private final ObjectMapper MAPPER = mapperWithModule();
153+
147154
public void testIntMethod() throws Exception {
148-
ObjectMapper mapper = mapperWithModule();
149-
IntBean bean = mapper.readValue("{\"x\":13}", IntBean.class);
155+
IntBean bean = MAPPER.readValue("{\"x\":13}", IntBean.class);
150156
assertEquals(13, bean._x);
151157
}
152158

153159
public void testMultiIntMethod() throws Exception {
154-
ObjectMapper mapper = mapperWithModule();
155-
IntsBean bean = mapper.readValue("{\"c\":3,\"a\":9,\"b\":111,\"e\":-9999,\"d\":1}", IntsBean.class);
160+
IntsBean bean = MAPPER.readValue("{\"c\":3,\"a\":9,\"b\":111,\"e\":-9999,\"d\":1}", IntsBean.class);
156161
assertEquals(9, bean._a);
157162
assertEquals(111, bean._b);
158163
assertEquals(3, bean._c);
@@ -161,20 +166,17 @@ public void testMultiIntMethod() throws Exception {
161166
}
162167

163168
public void testLongMethod() throws Exception {
164-
ObjectMapper mapper = mapperWithModule();
165-
LongBean bean = mapper.readValue("{\"x\":-1}", LongBean.class);
169+
LongBean bean = MAPPER.readValue("{\"x\":-1}", LongBean.class);
166170
assertEquals(-1, bean._x);
167171
}
168172

169173
public void testStringMethod() throws Exception {
170-
ObjectMapper mapper = mapperWithModule();
171-
StringBean bean = mapper.readValue("{\"x\":\"zoobar\"}", StringBean.class);
174+
StringBean bean = MAPPER.readValue("{\"x\":\"zoobar\"}", StringBean.class);
172175
assertEquals("zoobar", bean._x);
173176
}
174177

175178
public void testObjectMethod() throws Exception {
176-
ObjectMapper mapper = mapperWithModule();
177-
EnumBean bean = mapper.readValue("{\"x\":\"A\"}", EnumBean.class);
179+
EnumBean bean = MAPPER.readValue("{\"x\":\"A\"}", EnumBean.class);
178180
assertEquals(MyEnum.A, bean._x);
179181
}
180182

@@ -185,37 +187,32 @@ public void testObjectMethod() throws Exception {
185187
*/
186188

187189
public void testIntField() throws Exception {
188-
ObjectMapper mapper = mapperWithModule();
189-
IntFieldBean bean = mapper.readValue("{\"value\":-92}", IntFieldBean.class);
190+
IntFieldBean bean = MAPPER.readValue("{\"value\":-92}", IntFieldBean.class);
190191
assertEquals(-92, bean.x);
191192
}
192193

193194
public void testLongField() throws Exception {
194-
ObjectMapper mapper = mapperWithModule();
195-
LongFieldBean bean = mapper.readValue("{\"value\":-92}", LongFieldBean.class);
195+
LongFieldBean bean = MAPPER.readValue("{\"value\":-92}", LongFieldBean.class);
196196
assertEquals(-92, bean.value);
197197
}
198198

199199
public void testStringField() throws Exception {
200-
ObjectMapper mapper = mapperWithModule();
201-
StringFieldBean bean = mapper.readValue("{\"x\":\"\"}", StringFieldBean.class);
200+
StringFieldBean bean = MAPPER.readValue("{\"x\":\"\"}", StringFieldBean.class);
202201
assertEquals("", bean.x);
203202

204203
// also, null handling:
205-
bean = mapper.readValue("{\"x\":null}", StringFieldBean.class);
204+
bean = MAPPER.readValue("{\"x\":null}", StringFieldBean.class);
206205
assertNull(bean.x);
207206
}
208207

209208
public void testEnumField() throws Exception {
210-
ObjectMapper mapper = mapperWithModule();
211-
EnumFieldBean bean = mapper.readValue("{\"x\":\"C\"}", EnumFieldBean.class);
209+
EnumFieldBean bean = MAPPER.readValue("{\"x\":\"C\"}", EnumFieldBean.class);
212210
assertEquals(MyEnum.C, bean.x);
213211
}
214212

215213
// Verify [Issue#10], so that nulls do not get coerced to String "null"
216214
public void testStringAsObjectField() throws Exception {
217-
ObjectMapper mapper = mapperWithModule();
218-
StringAsObject bean = mapper.readValue("{\"value\":null}", StringAsObject.class);
215+
StringAsObject bean = MAPPER.readValue("{\"value\":null}", StringAsObject.class);
219216
assertNotNull(bean);
220217
assertNull(bean.value);
221218
}
@@ -228,21 +225,19 @@ public void testStringAsObjectField() throws Exception {
228225

229226
public void testFiveMinuteDoc() throws Exception
230227
{
231-
ObjectMapper abMapper = mapperWithModule();
232228
FiveMinuteUser input = new FiveMinuteUser("First", "Name", true,
233229
FiveMinuteUser.Gender.FEMALE, new byte[] { 1 } );
234-
String jsonAb = abMapper.writeValueAsString(input);
230+
String jsonAb = MAPPER.writeValueAsString(input);
235231

236-
FiveMinuteUser output = abMapper.readValue(jsonAb, FiveMinuteUser.class);
232+
FiveMinuteUser output = MAPPER.readValue(jsonAb, FiveMinuteUser.class);
237233
if (!output.equals(input)) {
238234
fail("Round-trip test failed: intermediate JSON = "+jsonAb);
239235
}
240236
}
241237

242238
public void testMixed() throws Exception
243239
{
244-
ObjectMapper mapper = mapperWithModule();
245-
MixedBean bean = mapper.readValue("{"
240+
MixedBean bean = MAPPER.readValue("{"
246241
+"\"stringField\":\"a\","
247242
+"\"string\":\"b\","
248243
+"\"intField\":3,"
@@ -268,8 +263,7 @@ public void testNonVoidProperty() throws Exception
268263
{
269264
final String json = "{ \"stringField\" : \"zoobar\", \"stringField2\" : \"barzoo\" }";
270265

271-
ObjectMapper mapper = new ObjectMapper();
272-
BeanWithNonVoidPropertySetter bean = mapper.readValue(json, BeanWithNonVoidPropertySetter.class);
266+
BeanWithNonVoidPropertySetter bean = MAPPER.readValue(json, BeanWithNonVoidPropertySetter.class);
273267
assertEquals("zoobar", bean.getStringField());
274268

275269
ObjectMapper abMapper = mapperWithModule(); // if I don't do this, the module won't be picked up
@@ -284,8 +278,7 @@ public void testBigNonVoidProperty() throws Exception
284278
{
285279
final String json = "{ \"stringField\" : \"zoobar\" }";
286280

287-
ObjectMapper mapper = new ObjectMapper();
288-
BigBeanWithNonVoidPropertySetter bean = mapper.readValue(json, BigBeanWithNonVoidPropertySetter.class);
281+
BigBeanWithNonVoidPropertySetter bean = MAPPER.readValue(json, BigBeanWithNonVoidPropertySetter.class);
289282
assertEquals("zoobar", bean.getStringField());
290283

291284
ObjectMapper abMapper = mapperWithModule(); // if I don't do this, the module won't be picked up
@@ -297,18 +290,38 @@ public void testBigNonVoidProperty() throws Exception
297290
// NOTE: failed with databind-2.5.0; fixed for 2.5.1
298291
public void testStringBuilder() throws Exception
299292
{
300-
ObjectMapper abMapper = mapperWithModule();
301-
StringBuilder sb = abMapper.readValue(quote("foobar"), StringBuilder.class);
293+
StringBuilder sb = MAPPER.readValue(quote("foobar"), StringBuilder.class);
302294
assertEquals("foobar", sb.toString());
303295
}
304296

305297
public void testBooleans() throws Exception
306298
{
307-
ObjectMapper mapper = mapperWithModule();
308-
BooleansBean bean = mapper.readValue(aposToQuotes("{'a':true, 'b':true}"),
299+
BooleansBean bean = MAPPER.readValue(aposToQuotes("{'a':true, 'b':true}"),
309300
BooleansBean.class);
310301
assertNotNull(bean);
311302
assertTrue(bean.a);
312303
assertEquals(Boolean.TRUE, bean._b);
313304
}
305+
306+
// for [module-afterburner#60]
307+
public void testProblemWithIndentation() throws Exception {
308+
final String JSON = "{\n"
309+
+" \"foos\" :\n"
310+
+" [\n"
311+
+" ]\n"
312+
+"}";
313+
314+
// First: read from String directly
315+
316+
Issue60Pojo pojo = MAPPER.readValue(JSON, Issue60Pojo.class);
317+
assertNotNull(pojo);
318+
assertNotNull(pojo.foos);
319+
assertEquals(0, pojo.foos.size());
320+
321+
// and then as bytes via InputStream
322+
pojo = MAPPER.readValue(JSON.getBytes("UTF-8"), Issue60Pojo.class);
323+
assertNotNull(pojo);
324+
assertNotNull(pojo.foos);
325+
assertEquals(0, pojo.foos.size());
326+
}
314327
}

0 commit comments

Comments
 (0)