use of com.alibaba.fastjson.parser.ParserConfig in project fastjson by alibaba.
the class Issue96 method xx_testCast.
public void xx_testCast() {
Page<Sub> page = new Page<Sub>(new Sub(1));
Type type = new TypeReference<Page<Sub>>() {
}.getType();
ParserConfig parserconfig = ParserConfig.getGlobalInstance();
// !!!! this will fail:
// !!!! com.alibaba.fastjson.JSONException: can not cast to : Page<Sub> TypeUtils.java:719
Page<Sub> page1 = TypeUtils.cast(page, type, parserconfig);
System.out.println(page1.sub.getClass());
}
use of com.alibaba.fastjson.parser.ParserConfig in project fastjson by alibaba.
the class NamingSerTest method test_camel.
public void test_camel() throws Exception {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
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.CamelCase;
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);
}
use of com.alibaba.fastjson.parser.ParserConfig in project fastjson by alibaba.
the class NamingSerTest method test_snake.
public void test_snake() throws Exception {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
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.SnakeCase;
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);
}
use of com.alibaba.fastjson.parser.ParserConfig in project fastjson by alibaba.
the class NamingSerTest method test_kebab.
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);
}
use of com.alibaba.fastjson.parser.ParserConfig in project fastjson by alibaba.
the class NamingSerTest method test_pascal.
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);
}
Aggregations