本文整理匯總了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();
}
}
示例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();
}
}
示例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());
}
示例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();
}
}
示例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());
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}