本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializeConfig类的典型用法代码示例。如果您正苦于以下问题:Java SerializeConfig类的具体用法?Java SerializeConfig怎么用?Java SerializeConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializeConfig类属于com.alibaba.fastjson.serializer包,在下文中一共展示了SerializeConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_pascal
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_pascal() throws Exception {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.PascalCase;
Model model = new Model();
model.personId = 1001;
String text = JSON.toJSONString(model, config);
Assert.assertEquals("{\"PersonId\":1001}", text);
ParserConfig parserConfig = new ParserConfig();
parserConfig.propertyNamingStrategy = PropertyNamingStrategy.PascalCase;
Model model2 = JSON.parseObject(text, Model.class, parserConfig);
Assert.assertEquals(model.personId, model2.personId);
Model model3 = JSON.parseObject(text, Model.class);
Assert.assertEquals(model.personId, model3.personId);
}
示例2: test_bean_2
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_bean_2() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", 123);
PO vo = TypeUtils.castToJavaBean(map, PO.class);
Assert.assertEquals(123, vo.id);
SerializeWriter out = new SerializeWriter();
try {
SerializeConfig config = new SerializeConfig();
JSONSerializer serializer = new JSONSerializer(out, config);
config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", "ID")));
serializer.write(vo);
Assert.assertEquals("{\"ID\":123}", out.toString());
} finally {
out.close();
}
}
示例3: test_0
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_0() throws Exception {
Object[] array = {new ModelA(), new ModelB() };
SerializeConfig config = new SerializeConfig();
config.addFilter(ModelA.class, //
new SimplePropertyPreFilter("name"));
config.addFilter(ModelB.class, //
new SimplePropertyPreFilter("id"));
String text2 = JSON.toJSONString(array, config);
Assert.assertEquals("[{},{\"id\":1002}]", text2);
String text = JSON.toJSONString(array);
Assert.assertEquals("[{\"id\":1001},{\"id\":1002}]", text);
}
示例4: toJSONString
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public static final String toJSONString(Object object, SerializeConfig config, SerializeFilter[] filters,
SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out, config);
for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
serializer.config(feature, true);
}
setFilter(serializer, filters);
serializer.write(object);
return out.toString();
} finally {
out.close();
}
}
示例5: test_codec_null
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_codec_null() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
Assert.assertEquals("{\"value\":null}", text);
ParserConfig config = new ParserConfig();
config.setAutoTypeSupport(true);
config.setAsmEnable(false);
V0 v1 = JSON.parseObject(text, V0.class, config, JSON.DEFAULT_PARSER_FEATURE);
Assert.assertEquals(v1.getValue(), v.getValue());
}
示例6: test_kebab
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_kebab() throws Exception {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.KebabCase;
Model model = new Model();
model.personId = 1001;
String text = JSON.toJSONString(model, config);
Assert.assertEquals("{\"person-id\":1001}", text);
ParserConfig parserConfig = new ParserConfig();
parserConfig.propertyNamingStrategy = PropertyNamingStrategy.KebabCase;
Model model2 = JSON.parseObject(text, Model.class, parserConfig);
Assert.assertEquals(model.personId, model2.personId);
Model model3 = JSON.parseObject(text, Model.class);
Assert.assertEquals(model.personId, model3.personId);
}
示例7: test_codec_null_asm
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_codec_null_asm() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(true);
String text = JSON.toJSONString(v, mapping,
SerializerFeature.WriteMapNullValue);
Assert.assertEquals("{\"value\":123}", text);
ParserConfig config = new ParserConfig();
config.setAsmEnable(false);
V0 v1 = JSON.parseObject(text, V0.class, config,
JSON.DEFAULT_PARSER_FEATURE);
Assert.assertEquals(v1.getValue(), v.getValue());
}
示例8: toJSONBytes
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public static final byte[] toJSONBytes(Object object, SerializeConfig config, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out, config);
for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.write(object);
return out.toBytes("UTF-8");
} finally {
out.close();
}
}
示例9: test_codec_null_1
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_codec_null_1() throws Exception {
V0 v = new V0();
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
Assert.assertEquals("{\"value\":null}", JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty));
Assert.assertEquals("{value:null}", JSON.toJSONStringZ(v, mapping, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty));
Assert.assertEquals("{value:null}", JSON.toJSONStringZ(v, mapping, SerializerFeature.UseSingleQuotes, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty));
Assert.assertEquals("{'value':null}", JSON.toJSONStringZ(v, mapping, SerializerFeature.UseSingleQuotes, SerializerFeature.QuoteFieldNames, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty));
}
示例10: convert
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public RequestBody convert(T value) throws IOException {
byte[] content = JSON.toJSONBytes(value
, serializeConfig == null
? SerializeConfig.globalInstance
: serializeConfig
, serializerFeatures == null
? SerializerFeature.EMPTY
: serializerFeatures
);
return RequestBody.create(MEDIA_TYPE, content);
}
示例11: FastJsonConfig
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
/**
* init param.
*/
public FastJsonConfig() {
this.charset = Charset.forName("UTF-8");
this.serializeConfig = SerializeConfig.getGlobalInstance();
this.parserConfig = new ParserConfig();
this.serializerFeatures = new SerializerFeature[] {
SerializerFeature.BrowserSecure
};
this.serializeFilters = new SerializeFilter[0];
this.features = new Feature[0];
}
示例12: JSONPath
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public JSONPath(String path, SerializeConfig serializeConfig, ParserConfig parserConfig){
if (path == null || path.length() == 0) {
throw new JSONPathException("json-path can not be null or empty");
}
this.path = path;
this.serializeConfig = serializeConfig;
this.parserConfig = parserConfig;
}
示例13: test_bytes_1
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_bytes_1() throws Exception {
VO vo = new VO();
vo.setValue(new byte[] {1, 2, 3});
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
SerializerFeature[] features = { SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty };
String text1 = JSON.toJSONString(vo, mapping, features);
Assert.assertEquals("{\"value\":\"AQID\"}", text1);
String text2 = JSON.toJSONString(vo, features);
Assert.assertEquals("{\"value\":\"AQID\"}", text2);
}
示例14: test_overflow_1
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_overflow_1() throws Exception {
Entity entity = new Entity();
entity.setSelf(entity);
String text = JSON.toJSONStringZ(entity, SerializeConfig.getGlobalInstance());
Entity entity2 = JSON.parseObject(text, Entity.class);
Assert.assertTrue(entity2 == entity2.getSelf());
}
示例15: test_codec_null
import com.alibaba.fastjson.serializer.SerializeConfig; //导入依赖的package包/类
public void test_codec_null() throws Exception {
User user = new User();
user.setValue(null);
SerializeConfig mapping = new SerializeConfig();
mapping.setAsmEnable(false);
String text = JSON.toJSONString(user, mapping, SerializerFeature.WriteMapNullValue);
User user1 = JSON.parseObject(text, User.class);
Assert.assertEquals(user1.getValue(), user.getValue());
}