From 08b18b153507964e53b50eaee1549d745bb03be8 Mon Sep 17 00:00:00 2001 From: Marcin Wolniewicz Date: Wed, 26 Sep 2018 18:32:32 +0200 Subject: [PATCH] Add BigInteger binding There seems to be most basic types in the Binder but BigInteger was missing, even though BigDecimal was present. Without the BigInteger binding fixtures for models using this type will not load. --- framework/src/play/data/binding/Binder.java | 6 ++++++ .../test-src/play/data/binding/BinderTest.java | 13 +++++++++++++ 2 files changed, 19 insertions(+) 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); + } }