Search in sources :

Example 56 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_7.

public void test_7() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.config(SerializerFeature.QuoteFieldNames, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    serializer.write(new User(33));
    Assert.assertEquals("{age:33}", serializer.getWriter().toString());
}
Also used : JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 57 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_2.

public void test_2() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.write(Collections.singletonMap("age", 33));
    Assert.assertEquals("{'age':33}", serializer.getWriter().toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 58 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_2_s.

public void test_2_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.write(Collections.singletonMap("age", 33));
    Assert.assertEquals("{'age':33}", serializer.getWriter().toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 59 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_8_s.

public void test_8_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.write(new User(33));
    Assert.assertEquals("{'age':33}", serializer.getWriter().toString());
}
Also used : JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 60 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_1.

public void test_1() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.write("abc");
    Assert.assertEquals("'abc'", serializer.getWriter().toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)263 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)206 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)54 HashMap (java.util.HashMap)48 NameFilter (com.alibaba.fastjson.serializer.NameFilter)36 ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)19 ArrayList (java.util.ArrayList)12 ListSerializer (com.alibaba.fastjson.serializer.ListSerializer)11 StringWriter (java.io.StringWriter)11 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)10 MapSerializer (com.alibaba.fastjson.serializer.MapSerializer)10 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)10 Map (java.util.Map)10 Date (java.util.Date)9 LinkedHashMap (java.util.LinkedHashMap)8 JSONException (com.alibaba.fastjson.JSONException)7 CollectionCodec (com.alibaba.fastjson.serializer.CollectionCodec)6 A (com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A)4 IOException (java.io.IOException)4 Color (java.awt.Color)3