0

I have the following JSON :

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

I try to deserialize this json with AutoBean, since i have problem to figure it out. I will like to go the reverse way.

Which interfaces can perfect match this JSON so that deserializing with AutoBean work?

where bean1, bean12, bean13 are interfaces and the values are all BigDecimal.

Community
  • 1
  • 1
3logy
  • 2,634
  • 8
  • 46
  • 99

1 Answers1

0

Check this sample. You must have corresponding interface(which has getter and setter for your values)

// 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();
      }
    }
Parvathy
  • 2,275
  • 3
  • 24
  • 39
  • Well! i already see this... but i can deserialize from JSON because apparently the problem is that these value are BigDecimal! – 3logy Mar 06 '13 at 13:27