Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions framework/src/play/data/binding/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions framework/test-src/play/data/binding/BinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> r = new HashMap<>();

BigInteger myBigInt = new BigInteger("12");
Integer myBigIntAsInteger = 12;
Unbinder.unBind(r, myBigIntAsInteger, "myBigInt", noAnnotations);
Map<String, String[]> r2 = fromUnbindMap2BindMap(r);
RootParamNode root = ParamNode.convert(r2);
assertThat(Binder.bind(root, "myBigInt", BigInteger.class, null, null)).isEqualTo(myBigInt);
}
}