From: Greg Brown [mailto:[email protected]] 
Sent: Friday, July 02, 2010 9:36 AM
To: [email protected]
Subject: Re: recommendation requested: json translation into objects

 

What recommendation do people have for converting json syntax to an object?
Should I grab a library? If so, any suggestions on which one?

 

If it is a bean, you can use JSONSerializer. See
org.apache.pivot.tests.JSONBeanTest for an example.

 

 

>>>Hmm.looked at the JSONSerializer again. I think it can work.  I looked at
the test, but my needs are from a JSON string to an object. The test showed
the object to string version.  Based on your suggestion, I would need
something like  below. I'll see how robust this is over time. Thanks!

 

BeanAdapter ba = new BeanAdapter(myObject);

theMap = JSONSerializer.toMap(myJsonSTring)

ba.putAll(theMap)

 

 

Ideally, I could register my converter and it gets called automatically when
I indicate the need for a conversion to a certain type.

 

Generally, we handle this by providing a string setter that performs the
conversion and calls the typed setter.

 

>>>Yup. I do this.  On a separate note, this is also a motivation for
potentially recommending a PivotStyle annotation so I can find all the
styles more easily. If multiple getters exist, its difficult to
programmatically scan and dedup and know the true style object
type-something useful for tooling. I still have to read javadoc to get
styling information.

Reply via email to