本文整理汇总了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);
}