Skip to content

Commit 866b2b4

Browse files
committed
Minor fix for #2215 implementation, related to #2978
1 parent 9dab814 commit 866b2b4

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/ValueInstantiator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ public Object createFromLong(DeserializationContext ctxt, long value) throws IOE
335335
public Object createFromBigInteger(DeserializationContext ctxt, BigInteger value) throws IOException
336336
{
337337
return ctxt.handleMissingInstantiator(getValueClass(),this,null,
338-
"no BigInteger-argument constructor/factory method to deserialize from Number value (%s)",
339-
value
338+
"no BigInteger-argument constructor/factory method to deserialize from Number value (%s)",
339+
value
340340
);
341341
}
342342

@@ -349,8 +349,8 @@ public Object createFromDouble(DeserializationContext ctxt, double value) throws
349349
public Object createFromBigDecimal(DeserializationContext ctxt, BigDecimal value) throws IOException
350350
{
351351
return ctxt.handleMissingInstantiator(getValueClass(),this,null,
352-
"no BigDecimal/double/Double-argument constructor/factory method to deserialize from Number value (%s)",
353-
value
352+
"no BigDecimal/double/Double-argument constructor/factory method to deserialize from Number value (%s)",
353+
value
354354
);
355355
}
356356

src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public Object createFromInt(DeserializationContext ctxt, int value) throws IOExc
368368
return _fromBigIntegerCreator.call1(arg);
369369
} catch (Throwable t0) {
370370
return ctxt.handleInstantiationProblem(_fromBigIntegerCreator.getDeclaringClass(),
371-
arg, rewrapCtorProblem(ctxt, t0)
371+
arg, rewrapCtorProblem(ctxt, t0)
372372
);
373373
}
374374
}
@@ -380,24 +380,23 @@ arg, rewrapCtorProblem(ctxt, t0)
380380
public Object createFromLong(DeserializationContext ctxt, long value) throws IOException
381381
{
382382
if (_fromLongCreator != null) {
383-
Object arg = Long.valueOf(value);
383+
Long arg = Long.valueOf(value);
384384
try {
385385
return _fromLongCreator.call1(arg);
386386
} catch (Throwable t0) {
387387
return ctxt.handleInstantiationProblem(_fromLongCreator.getDeclaringClass(),
388-
arg,
389-
rewrapCtorProblem(ctxt, t0)
388+
arg, rewrapCtorProblem(ctxt, t0)
390389
);
391390
}
392391
}
393392

394393
if (_fromBigIntegerCreator != null) {
395-
Object arg = BigInteger.valueOf(value);
394+
BigInteger arg = BigInteger.valueOf(value);
396395
try {
397396
return _fromBigIntegerCreator.call1(arg);
398397
} catch (Throwable t0) {
399398
return ctxt.handleInstantiationProblem(_fromBigIntegerCreator.getDeclaringClass(),
400-
arg, rewrapCtorProblem(ctxt, t0)
399+
arg, rewrapCtorProblem(ctxt, t0)
401400
);
402401
}
403402
}
@@ -408,12 +407,12 @@ arg, rewrapCtorProblem(ctxt, t0)
408407
@Override
409408
public Object createFromBigInteger(DeserializationContext ctxt, BigInteger value) throws IOException
410409
{
411-
if (_fromBigDecimalCreator != null) {
410+
if (_fromBigIntegerCreator != null) {
412411
try {
413412
return _fromBigIntegerCreator.call1(value);
414413
} catch (Throwable t) {
415414
return ctxt.handleInstantiationProblem(_fromBigIntegerCreator.getDeclaringClass(),
416-
value, rewrapCtorProblem(ctxt, t)
415+
value, rewrapCtorProblem(ctxt, t)
417416
);
418417
}
419418
}
@@ -425,22 +424,22 @@ value, rewrapCtorProblem(ctxt, t)
425424
public Object createFromDouble(DeserializationContext ctxt, double value) throws IOException
426425
{
427426
if(_fromDoubleCreator != null) {
428-
Object arg = Double.valueOf(value);
427+
Double arg = Double.valueOf(value);
429428
try {
430429
return _fromDoubleCreator.call1(arg);
431430
} catch (Throwable t0) {
432431
return ctxt.handleInstantiationProblem(_fromDoubleCreator.getDeclaringClass(),
433-
arg, rewrapCtorProblem(ctxt, t0));
432+
arg, rewrapCtorProblem(ctxt, t0));
434433
}
435434
}
436435

437436
if (_fromBigDecimalCreator != null) {
438-
Object arg = BigDecimal.valueOf(value);
437+
BigDecimal arg = BigDecimal.valueOf(value);
439438
try {
440439
return _fromBigDecimalCreator.call1(arg);
441440
} catch (Throwable t0) {
442441
return ctxt.handleInstantiationProblem(_fromBigDecimalCreator.getDeclaringClass(),
443-
arg, rewrapCtorProblem(ctxt, t0));
442+
arg, rewrapCtorProblem(ctxt, t0));
444443
}
445444
}
446445

@@ -455,7 +454,7 @@ public Object createFromBigDecimal(DeserializationContext ctxt, BigDecimal value
455454
return _fromBigDecimalCreator.call1(value);
456455
} catch (Throwable t) {
457456
return ctxt.handleInstantiationProblem(_fromBigDecimalCreator.getDeclaringClass(),
458-
value, rewrapCtorProblem(ctxt, t)
457+
value, rewrapCtorProblem(ctxt, t)
459458
);
460459
}
461460
}

src/test/java/com/fasterxml/jackson/databind/BaseMapTest.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.fasterxml.jackson.databind;
22

33
import java.io.*;
4-
import java.math.BigDecimal;
5-
import java.math.BigInteger;
64
import java.util.*;
75

86
import static org.junit.Assert.*;
@@ -59,29 +57,13 @@ public LongWrapper() { }
5957
public LongWrapper(long value) { l = value; }
6058
}
6159

62-
protected static class BigIntegerWrapper {
63-
public BigInteger i;
64-
65-
public BigIntegerWrapper() { }
66-
67-
public BigIntegerWrapper(final BigInteger value) { i = value; }
68-
}
69-
7060
protected static class DoubleWrapper {
7161
public double d;
7262

7363
public DoubleWrapper() { }
7464
public DoubleWrapper(double value) { d = value; }
7565
}
7666

77-
protected static class BigDecimalWrapper {
78-
public BigDecimal d;
79-
80-
public BigDecimalWrapper() { }
81-
82-
public BigDecimalWrapper(final BigDecimal value) { d = value; }
83-
}
84-
8567
/**
8668
* Simple wrapper around String type, usually to test value
8769
* conversions or wrapping

src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators.java

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import java.util.*;
66

77
import com.fasterxml.jackson.annotation.*;
8-
8+
import com.fasterxml.jackson.core.JsonParser;
99
import com.fasterxml.jackson.databind.*;
1010
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
11+
import com.fasterxml.jackson.databind.util.TokenBuffer;
1112

1213
/**
1314
* Unit tests for verifying that it is possible to annotate
@@ -172,7 +173,7 @@ static class NoArgFactoryBean {
172173
public static NoArgFactoryBean create() { return new NoArgFactoryBean(123); }
173174
}
174175

175-
// [Issue#208]
176+
// [databind#208]
176177
static class FromStringBean {
177178
protected String value;
178179

@@ -185,7 +186,25 @@ public static FromStringBean fromString(String s) {
185186
return new FromStringBean(s, false);
186187
}
187188
}
188-
189+
190+
// [databind#2215]
191+
protected static class BigIntegerWrapper {
192+
BigInteger _value;
193+
194+
public BigIntegerWrapper() { }
195+
196+
public BigIntegerWrapper(final BigInteger value) { _value = value; }
197+
}
198+
199+
// [databind#2215]
200+
protected static class BigDecimalWrapper {
201+
BigDecimal _value;
202+
203+
public BigDecimalWrapper() { }
204+
205+
public BigDecimalWrapper(final BigDecimal value) { _value = value; }
206+
}
207+
189208
/*
190209
/**********************************************************
191210
/* Annotated helper classes, mixed (creator and props)
@@ -333,14 +352,28 @@ public void testSimpleBooleanConstructor() throws Exception
333352

334353
public void testSimpleBigIntegerConstructor() throws Exception
335354
{
336-
final BigIntegerWrapper result = MAPPER.readValue("17", BigIntegerWrapper.class);
337-
assertEquals(new BigInteger("17"), result.i);
355+
// 10-Dec-2020, tatu: Small (magnitude) values will NOT trigger path
356+
// we want; must use something outside of Long range...
357+
358+
BigInteger INPUT = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.TEN);
359+
final BigIntegerWrapper result = MAPPER.readValue(INPUT.toString(), BigIntegerWrapper.class);
360+
assertEquals(INPUT, result._value);
338361
}
339362

340363
public void testSimpleBigDecimalConstructor() throws Exception
341364
{
342-
final BigDecimalWrapper result = MAPPER.readValue("42.5", BigDecimalWrapper.class);
343-
assertEquals(new BigDecimal("42.5"), result.d);
365+
// 10-Dec-2020, tatu: not sure we can ever trigger this with JSON;
366+
// but should be possible to handle via TokenBuffer?
367+
368+
BigDecimal INPUT = new BigDecimal("42.5");
369+
try (TokenBuffer buf = new TokenBuffer(null, false)) {
370+
buf.writeNumber(INPUT);
371+
try (JsonParser p = buf.asParser()) {
372+
final BigDecimalWrapper result = MAPPER.readValue(p,
373+
BigDecimalWrapper.class);
374+
assertEquals(INPUT, result._value);
375+
}
376+
}
344377
}
345378

346379
public void testSimpleFactory() throws Exception

0 commit comments

Comments
 (0)