本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializeWriter.toString方法的典型用法代码示例。如果您正苦于以下问题:Java SerializeWriter.toString方法的具体用法?Java SerializeWriter.toString怎么用?Java SerializeWriter.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.serializer.SerializeWriter
的用法示例。
在下文中一共展示了SerializeWriter.toString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJSONString
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public static final String toJSONString(Object object, SerializeFilter filter, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
for (SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
setFilter(serializer, filter);
serializer.write(object);
String serializeWriter = out.toString();
return serializeWriter;
} finally {
out.close();
}
}
示例2: test_namefilter
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Bean a = new Bean();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
示例3: test_4
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_4() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
if ("name".equals(name)) {
return false;
}
return true;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 3);
map.put("name", "chennp2008");
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"id\":3}", text);
}
示例4: test_3
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_3() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
if ("name".equals(name)) {
return true;
}
return false;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "chennp2008");
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"name\":\"chennp2008\"}", text);
}
示例5: test_namefilter_1
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_namefilter_1() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", '0');
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"ID\":\"0\"}", text);
}
示例6: test_2
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_2() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
if ("name".equals(name)) {
return true;
}
return false;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
A a = new A();
a.setName("chennp2008");
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"name\":\"chennp2008\"}", text);
}
示例7: test_namefilter_1
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_namefilter_1() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 0);
serializer.write(map);
String text = out.toString();
Assert.assertEquals("{\"ID\":0}", text);
}
示例8: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
return false;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
A a = new A();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{}", text);
}
示例9: marshalToString
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
/**
* 可以允许指定一些过滤字段进行生成json对象
*/
public static String marshalToString(Object obj, String... fliterFields) {
final List<String> propertyFliters = Arrays.asList(fliterFields);
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
return !propertyFliters.contains(name);
}
});
serializer.write(obj);
return out.toString();
} finally {
out.close();
}
}
示例10: test_namefilter
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_namefilter() throws Exception {
NameFilter filter = new NameFilter() {
public String process(Object source, String name, Object value) {
if (name.equals("id")) {
return "ID";
}
return name;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getNameFilters().add(filter);
Bean a = new Bean();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"ID\":0.0}", text);
}
示例11: test_1
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_1() throws Exception {
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
if ("id".equals(name)) {
Assert.assertTrue(value instanceof Long);
return true;
}
return false;
}
};
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.getPropertyFilters().add(filter);
A a = new A();
serializer.write(a);
String text = out.toString();
Assert.assertEquals("{\"id\":0}", text);
}
示例12: toJSONStringZ
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public static final String toJSONStringZ(Object object, SerializeConfig mapping, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter(features);
try {
new JSONSerializer(out, mapping).write(object);
String serializeWriter = out.toString();
return serializeWriter;
} finally {
out.close();
}
}