當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONSerializer.config方法代碼示例

本文整理匯總了Java中com.alibaba.fastjson.serializer.JSONSerializer.config方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONSerializer.config方法的具體用法?Java JSONSerializer.config怎麽用?Java JSONSerializer.config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.fastjson.serializer.JSONSerializer的用法示例。


在下文中一共展示了JSONSerializer.config方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toJSONString

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public static final String toJSONString(Object object) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.config(SerializerFeature.SortField, false);
        serializer.config(SerializerFeature.UseSingleQuotes, true);

        serializer.write(object);

        return out.toString();
    } catch (StackOverflowError e) {
        throw new JSONException("maybe circular references", e);
    } finally {
        out.close();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:MapTest.java

示例2: toJSONBytes

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public static final byte[] toJSONBytes(Object object, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
            serializer.config(feature, true);
        }

        serializer.write(object);

        return out.toBytes("UTF-8");
    } finally {
        out.close();
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:17,代碼來源:JSON.java

示例3: test_9_s

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_9_s() throws Exception {
    JSONSerializer serializer = new JSONSerializer();

    serializer.config(SerializerFeature.QuoteFieldNames, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
    serializer.config(SerializerFeature.WriteMapNullValue, false);
    Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.WriteMapNullValue));

    SerializeWriter out = new SerializeWriter();

    Map map = new LinkedHashMap();
    map.put("a", null);
    map.put("age", 33);
    map.put("c", null);

    serializer.write(map);

    Assert.assertEquals("{age:33}", serializer.getWriter().toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:JSONSerializerFeatureTest.java

示例4: toJSONString

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
            serializer.config(feature, true);
        }

        serializer.config(SerializerFeature.WriteDateUseDateFormat, true);

        setFilter(serializer, filter);

        serializer.write(object);

        return out.toString();
    } finally {
        out.close();
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:21,代碼來源:JSON.java

示例5: test_0

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_0() throws Exception {
    JSONSerializer serializer = new JSONSerializer();

    int size = JSONSerializerMapTest.size(serializer.getMapping());
    serializer.config(SerializerFeature.WriteEnumUsingToString, false);
    serializer.config(SerializerFeature.WriteEnumUsingName, false);
    serializer.write(Type.A);

    Assert.assertTrue(size < JSONSerializerMapTest.size(serializer.getMapping()));

    Assert.assertEquals(Integer.toString(Type.A.ordinal()), serializer.getWriter().toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:JSONSerializerTest2.java

示例6: test_3

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_3() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.write(new A(Type.B));

    Assert.assertEquals("{\"type\":\"B\"}", serializer.getWriter().toString());

    A a = JSON.parseObject(serializer.getWriter().toString(), A.class);
    Assert.assertEquals(a.getType(), Type.B);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:JSONSerializerTest2.java

示例7: test_3

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_3() throws Exception {
	SerializeWriter out = new SerializeWriter();
	JSONSerializer serializer = new JSONSerializer(out);
	serializer.config(SerializerFeature.UseSingleQuotes, true);

	serializer.write(new TestEntity("張三"));
	Assert.assertEquals("{'value':'張三'}", out.toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:StringSerializerTest.java

示例8: test_2

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_2() throws Exception {
    SerializeWriter out = new SerializeWriter();

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294552193000L));

    Assert.assertEquals("\"2011-01-09T13:49:53+08:00\"", out.toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:DateTest.java

示例9: test_4

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_4() throws Exception {
    SerializeWriter out = new SerializeWriter();

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    serializer.config(SerializerFeature.UseSingleQuotes, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294502400000L));

    Assert.assertEquals("'2011-01-09+08:00'", out.toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:DateTest.java

示例10: toJSONString

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public static final String toJSONString(Object object, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        for (SerializerFeature feature : features) {
            serializer.config(feature, true);
        }
        serializer.write(object);
        String serializeWriter = out.toString();
        return serializeWriter;
    } finally {
        out.close();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:15,代碼來源:JSON.java

示例11: writeObject

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void writeObject(Object obj) throws IOException {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.write(obj);
    out.writeTo(writer);
    writer.println();
    writer.flush();
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:10,代碼來源:FastJsonObjectOutput.java

示例12: test_7

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_7() throws Exception {
    SerializeWriter out = new SerializeWriter();

    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.UseISO8601DateFormat, true);
    Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
    serializer.write(new Date(1294506000000L));

    Assert.assertEquals("\"2011-01-09T01:00:00+08:00\"", out.toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:DateTest.java

示例13: test_6

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:JSONSerializerFeatureTest.java

示例14: test_date_3

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
public void test_date_3() throws Exception {
    SerializeWriter out = new SerializeWriter();
    SerializeConfig config = new SerializeConfig();
    JSONSerializer serializer = new JSONSerializer(out, config);

    serializer.config(SerializerFeature.WriteClassName, true);
    serializer.write(new VO());

    Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.serializer.DateFormatSerializerTest$VO\"}",
                        out.toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:DateFormatSerializerTest.java

示例15: serialize

import com.alibaba.fastjson.serializer.JSONSerializer; //導入方法依賴的package包/類
@Override
public byte[] serialize(Object data) throws IOException {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.config(SerializerFeature.WriteEnumUsingToString, true);
    serializer.config(SerializerFeature.WriteClassName, true);
    serializer.write(data);
    return out.toBytes(null);
}
 
開發者ID:chenxh,項目名稱:rpc,代碼行數:10,代碼來源:FastJsonSerialization.java


注:本文中的com.alibaba.fastjson.serializer.JSONSerializer.config方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。