我有以下JSON:
{
"bean1": {
"bean12": {
"value1": 4500,
"value2": 1500
},
"bean13": {
"value1": 1550,
"value2": 550
}
}
}
我尝试使用AutoBean反序列化这个json,因为我有problem来解决它。我想反过来。
哪些接口可以完美匹配此JSON,以便使用AutoBean进行反序列化工作?
其中bean1,bean12,bean13是接口,值都是BigDecimal。
答案 0 :(得分:0)
检查此样本。您必须具有相应的界面(其值具有getter和setter)
// Declare any bean-like interface with matching getters and setters, no base type is necessary
interface Person {
Address getAddress();
String getName();
void setName(String name);
void setAddress(Address a);
}
interface Address {
// Other properties, as above
}
// Declare the factory type
interface MyFactory extends AutoBeanFactory {
AutoBean<Address> address();
AutoBean<Person> person();
}
class DoSomething() {
// Instantiate the factory
MyFactory factory = GWT.create(MyFactory.class);
// In non-GWT code, use AutoBeanFactorySource.create(MyFactory.class);
Person makePerson() {
// Construct the AutoBean
AutoBean<Person> person = factory.person();
// Return the Person interface shim
return person.as();
}
String serializeToJson(Person person) {
// Retrieve the AutoBean controller
AutoBean<Person> bean = AutoBeanUtils.getAutoBean(person);
return AutoBeanCodex.encode(bean).getPayload();
}
Person deserializeFromJson(String json) {
AutoBean<Person> bean = AutoBeanCodex.decode(factory, Person.class, json);
return bean.as();
}
}