Package com.alibaba.json.bvt.serializer

Source Code of com.alibaba.json.bvt.serializer.DoubleTest_custom

package com.alibaba.json.bvt.serializer;

import java.text.DecimalFormat;

import junit.framework.TestCase;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.DoubleSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;

public class DoubleTest_custom extends TestCase {

    public void test_0() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.put(Double.class, new DoubleSerializer(new DecimalFormat("###.##")));
        Assert.assertEquals("1.12", JSON.toJSONString(1.123456789D, config));
    }
   
    public void test_1() throws Exception {
        SerializeConfig config = new SerializeConfig();
        config.put(Double.class, new DoubleSerializer("###.###"));
        Assert.assertEquals("1.123", JSON.toJSONString(1.123456789D, config));
    }
}
TOP

Related Classes of com.alibaba.json.bvt.serializer.DoubleTest_custom

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.