Search in sources :

Example 51 with JSONSerializer

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

the class IntegerArrayEncodeTest method test_3_s.

public void test_3_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    StringBuilder sb = new StringBuilder();
    sb.append('[');
    int len = 1000;
    Integer[] array = new Integer[len];
    for (int i = 0; i < array.length; ++i) {
        array[i] = i;
        if (i != 0) {
            sb.append(',');
        }
        sb.append(i);
    }
    sb.append(']');
    serializer.write(array);
    Assert.assertEquals(sb.toString(), out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 52 with JSONSerializer

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

the class JSONSerializerDeprecatedTest method test_.

public void test_() throws Exception {
    JSONSerializer ser = new JSONSerializer(new SerializeConfig());
    ser.setDateFormat(new ISO8601DateFormat());
    Assert.assertEquals(null, ser.getDateFormatPattern());
    ser.close();
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) ISO8601DateFormat(com.fasterxml.jackson.databind.util.ISO8601DateFormat) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 53 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_0.

public void test_0() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 54 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_4_s.

public void test_4_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    serializer.config(SerializerFeature.QuoteFieldNames, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    serializer.write(Collections.singletonMap("a\nge", 33));
    Assert.assertEquals("{\"a\\nge\":33}", serializer.getWriter().toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 55 with JSONSerializer

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

the class JSONSerializerFeatureTest method test_6.

public void test_6() throws Exception {
    JSONSerializer serializer = new JSONSerializer(new SerializeWriter());
    serializer.config(SerializerFeature.QuoteFieldNames, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseSingleQuotes));
    serializer.write(Collections.singletonMap("a'ge", 33));
    Assert.assertEquals("{'a\\'ge':33}", 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