哪些接口表示要从JSON反序列化到AutoBean



我有以下JSON:

    {
   "bean1": {
    "bean12": {
        "value1": 4500,
        "value2": 1500
    },
    "bean13": {
        "value1": 1550,
        "value2": 550
    }
   } 
  }

我试着用AutoBean反序列化这个json,因为我有问题要弄清楚。我想走相反的路。

哪些接口可以完美匹配这个JSON,以便与AutoBean反序列化工作?

其中bean1, bean12, bean13为接口,值均为BigDecimal

检查这个示例。你必须有相应的接口(有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();
      }
    }

最新更新