本文整理了Java中jodd.json.JsonSerializer.createJsonContext()
方法的一些代码示例,展示了JsonSerializer.createJsonContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonSerializer.createJsonContext()
方法的具体详情如下:
包路径:jodd.json.JsonSerializer
类名称:JsonSerializer
方法名:createJsonContext
[英]Creates new JSON context.
[中]创建新的JSON上下文。
代码示例来源:origin: oblac/jodd
/**
* Serializes object into provided appendable.
*/
public void serialize(final Object source, final Appendable target) {
JsonContext jsonContext = createJsonContext(target);
jsonContext.serialize(source);
}
代码示例来源:origin: oblac/jodd
@Test
void testConvertObjectToMapSimple() {
Hill hill = new Hill();
hill.setHeight("173");
hill.setName("JoddHillWood");
final Map<String, Object> target = new HashMap<>();
JsonContext jsonContext = new JsonSerializer().createJsonContext(null);
BeanSerializer beanSerializer = new BeanSerializer(jsonContext, hill) {
@Override
protected void onSerializableProperty(String propertyName, Class propertyType, Object value) {
target.put(propertyName, value);
}
};
beanSerializer.serialize();
assertEquals(1, target.size());
assertEquals("173", target.get("height"));
}
代码示例来源:origin: oblac/jodd
@Test
void testConvertPersonToMap() {
Person jodder = new DataCreator().createJodder();
final Map<String, Object> target = new HashMap<>();
JsonContext jsonContext = new JsonSerializer().createJsonContext(null);
BeanSerializer beanSerializer = new BeanSerializer(jsonContext, jodder) {
@Override
protected void onSerializableProperty(String propertyName, Class propertyType, Object value) {
target.put(propertyName, value);
}
};
beanSerializer.serialize();
assertEquals(6, target.size());
assertSame(jodder.getBirthdate(), target.get("birthdate"));
assertSame(jodder.getFirstBaseBallGame(), target.get("firstBaseBallGame"));
assertSame(jodder.getLastname(), target.get("lastname"));
assertSame(jodder.getFirstname(), target.get("firstname"));
assertSame(jodder.getHome(), target.get("home"));
assertSame(jodder.getWork(), target.get("work"));
}
代码示例来源:origin: oblac/jodd
@Test
void testConvertPersonToMap2() {
Person jodder = new DataCreator().createJodder();
final Map<String, Object> target = new HashMap<>();
JsonContext jsonContext = new JsonSerializer()
.include("phones")
.excludeTypes(Address.class)
.createJsonContext(null);
BeanSerializer beanSerializer = new BeanSerializer(jsonContext, jodder) {
@Override
protected void onSerializableProperty(String propertyName, Class propertyType, Object value) {
target.put(propertyName, value);
}
};
beanSerializer.serialize();
assertEquals(5, target.size());
assertSame(jodder.getBirthdate(), target.get("birthdate"));
assertSame(jodder.getFirstBaseBallGame(), target.get("firstBaseBallGame"));
assertSame(jodder.getLastname(), target.get("lastname"));
assertSame(jodder.getFirstname(), target.get("firstname"));
assertSame(jodder.getPhones(), target.get("phones"));
}
内容来源于网络,如有侵权,请联系作者删除!