Search in sources :

Example 96 with BigInteger

use of java.math.BigInteger in project fastjson by alibaba.

the class Bug_7 method test_bigintegerArray.

public void test_bigintegerArray() throws Exception {
    BigInteger[] a = new BigInteger[] { new BigInteger("214748364812"), new BigInteger("2147483648123") };
    String text = JSON.toJSONString(a);
    Assert.assertEquals("[214748364812,2147483648123]", text);
    JSON json = (JSON) JSON.parse(text);
    Assert.assertEquals("[214748364812,2147483648123]", json.toJSONString());
}
Also used : BigInteger(java.math.BigInteger) JSON(com.alibaba.fastjson.JSON)

Example 97 with BigInteger

use of java.math.BigInteger in project fastjson by alibaba.

the class DefaultExtJSONParserTest_1 method f_test_2.

public void f_test_2() throws Exception {
    TestEntity a = new TestEntity();
    a.setF1(true);
    a.setF2(Boolean.TRUE);
    a.setF3((byte) 123);
    a.setF4((byte) 123);
    a.setF5((short) 123);
    a.setF6((short) 123);
    a.setF7((int) 123);
    a.setF8((int) 123);
    a.setF9((long) 123);
    a.setF10((long) 123);
    a.setF11(new BigInteger("123"));
    a.setF12(new BigDecimal("123"));
    a.setF13("abc");
    a.setF14(null);
    a.setF15(12.34F);
    a.setF16(12.35F);
    a.setF17(12.345D);
    a.setF18(12.345D);
    String text = JSON.toJSONString(a);
    System.out.println(text);
    TestEntity b = new TestEntity();
    {
        DefaultJSONParser parser = new DefaultJSONParser(text);
        parser.parseObject(b);
    }
    Assert.assertEquals("f1", a.isF1(), b.isF1());
    Assert.assertEquals("f2", a.getF2(), b.getF2());
    Assert.assertEquals("f3", a.getF3(), b.getF3());
    Assert.assertEquals("f4", a.getF4(), b.getF4());
    Assert.assertEquals("f5", a.getF5(), b.getF5());
    Assert.assertEquals("f6", a.getF6(), b.getF6());
    Assert.assertEquals("f7", a.getF7(), b.getF7());
    Assert.assertEquals("f8", a.getF8(), b.getF8());
    Assert.assertEquals("f9", a.getF9(), b.getF9());
    Assert.assertEquals(a.getF10(), b.getF10());
    Assert.assertEquals(a.getF11(), b.getF11());
    Assert.assertEquals(a.getF12(), b.getF12());
    Assert.assertEquals(a.getF13(), b.getF13());
    Assert.assertEquals(a.getF14(), b.getF14());
    Assert.assertEquals(a.getF15(), b.getF15());
    Assert.assertEquals(a.getF16(), b.getF16());
    Assert.assertEquals(a.getF17(), b.getF17());
    Assert.assertEquals(a.getF18(), b.getF18());
}
Also used : TestEntity(com.alibaba.json.test.entity.TestEntity) BigInteger(java.math.BigInteger) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) BigDecimal(java.math.BigDecimal)

Example 98 with BigInteger

use of java.math.BigInteger in project fastjson by alibaba.

the class BigIntegerDeserializerTest method test_1.

public void test_1() throws Exception {
    BigInteger value = JSON.parseObject("'123'", BigInteger.class);
    Assert.assertEquals(new BigInteger("123"), value);
}
Also used : BigInteger(java.math.BigInteger)

Example 99 with BigInteger

use of java.math.BigInteger in project fastjson by alibaba.

the class TypeUtilsTest method test_cast_to_BigInteger.

public void test_cast_to_BigInteger() throws Exception {
    JSONObject json = new JSONObject();
    json.put("id", 1);
    Assert.assertEquals(new BigInteger("1"), json.getObject("id", BigInteger.class));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BigInteger(java.math.BigInteger)

Example 100 with BigInteger

use of java.math.BigInteger in project fastjson by alibaba.

the class IntegerParseTest method test_b.

public void test_b() throws Exception {
    Assert.assertEquals(Long.valueOf(12), JSON.parseObject("12B", long.class));
    Assert.assertEquals(Integer.valueOf(12), JSON.parseObject("12B", int.class));
    Assert.assertEquals(new Short((short) 12), JSON.parseObject("12B", short.class));
    Assert.assertEquals(new Byte((byte) 12), JSON.parseObject("12B", byte.class));
    Assert.assertEquals(new Float(12), JSON.parseObject("12B", float.class));
    Assert.assertEquals(new Double(12), JSON.parseObject("12B", double.class));
    Assert.assertEquals(new BigDecimal(12), JSON.parseObject("12B", BigDecimal.class));
    Assert.assertEquals(new BigInteger("12"), JSON.parseObject("12B", BigInteger.class));
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Aggregations

BigInteger (java.math.BigInteger)3139 BigDecimal (java.math.BigDecimal)604 Test (org.junit.Test)207 IOException (java.io.IOException)101 ArrayList (java.util.ArrayList)95 MessageDigest (java.security.MessageDigest)93 RoundingMode (java.math.RoundingMode)88 Date (java.util.Date)72 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)71 MathContext (java.math.MathContext)70 Random (java.util.Random)62 QuickTest (com.hazelcast.test.annotation.QuickTest)47 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 KeyFactory (java.security.KeyFactory)45 HashMap (java.util.HashMap)42 X509Certificate (java.security.cert.X509Certificate)39 EllipticCurve (java.security.spec.EllipticCurve)39 List (java.util.List)39 GwtIncompatible (com.google.common.annotations.GwtIncompatible)36 SecureRandom (java.security.SecureRandom)35