Search in sources :

Example 71 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class FeaturesTest5 method test_1.

public void test_1() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.setAsmEnable(true);
    String text = JSON.toJSONString(new Entity(), config);
    Assert.assertEquals("{\"value\":false}", text);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig)

Example 72 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class FeaturesTest6 method test_0.

public void test_0() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.setAsmEnable(false);
    String text = JSON.toJSONString(new Entity(), config);
    Assert.assertEquals("{\"value\":[]}", text);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig)

Example 73 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class FeaturesTest7 method test_0.

public void test_0() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.setAsmEnable(false);
    String text = JSON.toJSONString(new Entity(), config);
    Assert.assertEquals("{\"value\":\"SECONDS\"}", text);
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig)

Example 74 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class TypeUtilsTest_castToJavaBean method test_bean_2.

public void test_bean_2() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    PO vo = TypeUtils.castToJavaBean(map, PO.class);
    Assert.assertEquals(123, vo.id);
    SerializeWriter out = new SerializeWriter();
    try {
        SerializeConfig config = new SerializeConfig();
        JSONSerializer serializer = new JSONSerializer(out, config);
        config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", "ID")));
        serializer.write(vo);
        Assert.assertEquals("{\"ID\":123}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) HashMap(java.util.HashMap) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) JavaBeanSerializer(com.alibaba.fastjson.serializer.JavaBeanSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 75 with SerializeConfig

use of com.alibaba.fastjson.serializer.SerializeConfig in project fastjson by alibaba.

the class BooleanFieldSerializerTest_primitive method test_codec_no_asm.

public void test_codec_no_asm() throws Exception {
    Entity v = new Entity();
    SerializeConfig mapping = new SerializeConfig();
    mapping.setAsmEnable(false);
    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    Assert.assertEquals("{\"value\":false}", text);
    Entity v1 = JSON.parseObject(text, Entity.class);
    Assert.assertEquals(v.getValue(), v1.getValue());
}
Also used : Entity(com.alibaba.json.bvt.serializer.BooleanFieldSerializerTest.Entity) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig)

Aggregations

SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)191 Date (java.util.Date)16 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)13 SimpleDateFormat (java.text.SimpleDateFormat)12 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)10 SimpleDateFormatSerializer (com.alibaba.fastjson.serializer.SimpleDateFormatSerializer)8 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)6 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)4 HashMap (java.util.HashMap)4 DoubleSerializer (com.alibaba.fastjson.serializer.DoubleSerializer)3 SerializerFeature (com.alibaba.fastjson.serializer.SerializerFeature)3 SimplePropertyPreFilter (com.alibaba.fastjson.serializer.SimplePropertyPreFilter)3 AfterFilter (com.alibaba.fastjson.serializer.AfterFilter)2 BeforeFilter (com.alibaba.fastjson.serializer.BeforeFilter)2 NameFilter (com.alibaba.fastjson.serializer.NameFilter)2 PascalNameFilter (com.alibaba.fastjson.serializer.PascalNameFilter)2 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)2 ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)2 BigDecimal (java.math.BigDecimal)2 DecimalFormat (java.text.DecimalFormat)2