@@ -249,7 +249,19 @@ public ValueClassXY build() {
249
249
return null ;
250
250
}
251
251
}
252
-
252
+
253
+ // [databind#777]
254
+ @ JsonDeserialize (builder = SelfBuilder777 .class )
255
+ @ JsonPOJOBuilder (buildMethodName = "" , withPrefix = "with" )
256
+ static class SelfBuilder777 {
257
+ public int x ;
258
+
259
+ public SelfBuilder777 withX (int value ) {
260
+ x = value ;
261
+ return this ;
262
+ }
263
+ }
264
+
253
265
// [databind#822]
254
266
@ JsonPOJOBuilder (buildMethodName = "build" , withPrefix = "with" )
255
267
static class ValueBuilder822
@@ -289,12 +301,12 @@ public ValueClass822(int x, Map<String,Object> stuff) {
289
301
/**********************************************************
290
302
*/
291
303
292
- private final ObjectMapper mapper = new ObjectMapper ();
304
+ private final ObjectMapper MAPPER = new ObjectMapper ();
293
305
294
306
public void testSimple () throws Exception
295
307
{
296
308
String json = "{\" x\" :1,\" y\" :2}" ;
297
- Object o = mapper .readValue (json , ValueClassXY .class );
309
+ Object o = MAPPER .readValue (json , ValueClassXY .class );
298
310
assertNotNull (o );
299
311
assertSame (ValueClassXY .class , o .getClass ());
300
312
ValueClassXY value = (ValueClassXY ) o ;
@@ -306,7 +318,7 @@ public void testSimple() throws Exception
306
318
public void testMultiAccess () throws Exception
307
319
{
308
320
String json = "{\" c\" :3,\" a\" :2,\" b\" :-9}" ;
309
- ValueClassABC value = mapper .readValue (json , ValueClassABC .class );
321
+ ValueClassABC value = MAPPER .readValue (json , ValueClassABC .class );
310
322
assertNotNull (value );
311
323
// note: ctor adds one to both values
312
324
assertEquals (value .a , 2 );
@@ -318,23 +330,23 @@ public void testMultiAccess() throws Exception
318
330
public void testImmutable () throws Exception
319
331
{
320
332
final String json = "{\" value\" :13}" ;
321
- ValueImmutable value = mapper .readValue (json , ValueImmutable .class );
333
+ ValueImmutable value = MAPPER .readValue (json , ValueImmutable .class );
322
334
assertEquals (13 , value .value );
323
335
}
324
336
325
337
// test with custom 'with-prefix'
326
338
public void testCustomWith () throws Exception
327
339
{
328
340
final String json = "{\" value\" :1}" ;
329
- ValueFoo value = mapper .readValue (json , ValueFoo .class );
341
+ ValueFoo value = MAPPER .readValue (json , ValueFoo .class );
330
342
assertEquals (1 , value .value );
331
343
}
332
344
333
345
// test to ensure @JsonCreator also work
334
346
public void testWithCreator () throws Exception
335
347
{
336
348
final String json = "{\" a\" :1,\" c\" :3,\" b\" :2}" ;
337
- CreatorValue value = mapper .readValue (json , CreatorValue .class );
349
+ CreatorValue value = MAPPER .readValue (json , CreatorValue .class );
338
350
assertEquals (1 , value .a );
339
351
assertEquals (2 , value .b );
340
352
assertEquals (3 , value .c );
@@ -345,22 +357,22 @@ public void testWithCreator() throws Exception
345
357
public void testBuilderMethodReturnMoreGeneral () throws Exception
346
358
{
347
359
final String json = "{\" x\" :1}" ;
348
- ValueInterface value = mapper .readValue (json , ValueInterface .class );
360
+ ValueInterface value = MAPPER .readValue (json , ValueInterface .class );
349
361
assertEquals (2 , value .getX ());
350
362
}
351
363
352
364
public void testBuilderMethodReturnMoreSpecific () throws Exception
353
365
{
354
366
final String json = "{\" x\" :1}" ;
355
- ValueInterface2 value = mapper .readValue (json , ValueInterface2 .class );
367
+ ValueInterface2 value = MAPPER .readValue (json , ValueInterface2 .class );
356
368
assertEquals (2 , value .getX ());
357
369
}
358
370
359
371
public void testBuilderMethodReturnInvalidType () throws Exception
360
372
{
361
373
final String json = "{\" x\" :1}" ;
362
374
try {
363
- mapper .readValue (json , ValueClassWrongBuildType .class );
375
+ MAPPER .readValue (json , ValueClassWrongBuildType .class );
364
376
fail ("Missing expected JsonProcessingException exception" );
365
377
} catch (JsonProcessingException e ) {
366
378
assertTrue (
@@ -369,10 +381,18 @@ public void testBuilderMethodReturnInvalidType() throws Exception
369
381
}
370
382
}
371
383
384
+ public void testSelfBuilder777 () throws Exception
385
+ {
386
+ SelfBuilder777 result = MAPPER .readValue (aposToQuotes ("{'x':3}'" ),
387
+ SelfBuilder777 .class );
388
+ assertNotNull (result );
389
+ assertEquals (3 , result .x );
390
+ }
391
+
372
392
public void testWithAnySetter822 () throws Exception
373
393
{
374
394
final String json = "{\" extra\" :3,\" foobar\" :[ ],\" x\" :1,\" name\" :\" bob\" }" ;
375
- ValueClass822 value = mapper .readValue (json , ValueClass822 .class );
395
+ ValueClass822 value = MAPPER .readValue (json , ValueClass822 .class );
376
396
assertEquals (1 , value .x );
377
397
assertNotNull (value .stuff );
378
398
assertEquals (3 , value .stuff .size ());
@@ -383,4 +403,6 @@ public void testWithAnySetter822() throws Exception
383
403
assertTrue (ob instanceof List );
384
404
assertTrue (((List <?>) ob ).isEmpty ());
385
405
}
406
+
407
+
386
408
}
0 commit comments