Re: [json-lib-user] JSONObject.toBean() in a Object with an Array Property
Brought to you by:
aalmiray
|
From: Everton A. <ton...@gm...> - 2010-11-18 15:42:56
|
There is getters and setters, don't worry about it, i just ommited them in
the snippet code.
You were right, it was capitalization. I thought it wasn't because of the
output it sent:
18/11/2010 13:36:56 net.sf.json.JSONObject toBean
AVISO: Tried to assign property Name:java.lang.String to bean of class
Product
18/11/2010 13:36:56 net.sf.json.JSONObject toBean
AVISO: Tried to assign property Expiry:java.lang.String to bean of class
Product
18/11/2010 13:36:56 net.sf.json.JSONObject toBean
AVISO: Tried to assign property Price:java.lang.Float to bean of class
Product
It seemed that it worked on every property except for "Sizes" (where it
throwed an exception). It pointed me to a wrong direction.
Anyways... is there any way to workaround this? I sort of can't change how
this JSON string is created, and i would like to use the automagic bean
transformer.
Thank you
_______________________
Everton Agner Ramos
2010/11/18 Everton Agner <ton...@gm...>
> Hi!
>
> I need to convert this JSON string
>
>
> {"Name":"Apple","Expiry":"\/Date(1230429600000-0200)\/","Price":3.99,"Sizes":["Small","Medium","Large"]}
>
> To this JavaBean
>
> public class Product
> {
> private String name;
> private Date expiry;
> private BigDecimal price;
> private String[] sizes;
> }
>
> With this code
>
> JSONObject json = JSONObject.fromObject(jsonText);
>
> Product p = (Product) JSONObject.toBean(json, Product.class);
>
>
> And I'm getting this exception:
>
> Exception in thread "main" net.sf.json.JSONException:
> java.lang.NoSuchMethodException: Unknown property 'Sizes' on class 'class
> Product'
>
>
> I don't think it's because os case sensitivity (it's an Object created on
> C#, that's why the properties are Pascal Case).
>
> What do i need to do to make this work? I searched for it and got
> nothing...
>
>
> Thanks!
>
> _______________________
> Everton Agner Ramos
>
|