0
4

1 回答 1

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();
      }
    }
于 2013-03-06T13:19:20.460 回答