diff --git a/framework/src/play/data/binding/Binder.java b/framework/src/play/data/binding/Binder.java index 4463a97d28..6bf216c87a 100644 --- a/framework/src/play/data/binding/Binder.java +++ b/framework/src/play/data/binding/Binder.java @@ -14,6 +14,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.*; import java.math.BigDecimal; +import java.math.BigInteger; import java.text.ParseException; import java.time.LocalDateTime; import java.util.*; @@ -790,6 +791,11 @@ private static Object internalDirectBind(String name, Annotation[] annotations, return nullOrEmpty ? null : new BigDecimal(value); } + // BigInteger binding + if (clazz.equals(BigInteger.class)) { + return nullOrEmpty ? null : new BigInteger(value); + } + // boolean or Boolean binding if (clazz.getName().equals("boolean") || clazz.equals(Boolean.class)) { if (nullOrEmpty) { diff --git a/framework/test-src/play/data/binding/BinderTest.java b/framework/test-src/play/data/binding/BinderTest.java index 0c3abbf993..cbe9dd5d35 100644 --- a/framework/test-src/play/data/binding/BinderTest.java +++ b/framework/test-src/play/data/binding/BinderTest.java @@ -9,6 +9,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.*; import static java.math.BigDecimal.TEN; @@ -331,6 +332,18 @@ public Object bind(String name, Annotation[] annotations, String value, Class ac return new BigDecimal(value).add(TEN); } } + + @Test + public void verify_binding_of_BigInteger() { + Map r = new HashMap<>(); + + BigInteger myBigInt = new BigInteger("12"); + Integer myBigIntAsInteger = 12; + Unbinder.unBind(r, myBigIntAsInteger, "myBigInt", noAnnotations); + Map r2 = fromUnbindMap2BindMap(r); + RootParamNode root = ParamNode.convert(r2); + assertThat(Binder.bind(root, "myBigInt", BigInteger.class, null, null)).isEqualTo(myBigInt); + } }