Re: [json-lib-user] Problems with .toJava
Brought to you by:
aalmiray
|
From: Kiril <kir...@gm...> - 2008-05-10 06:56:15
|
May be attaching the json string will help:
{"groups":[{"comparison":"And","fields":[{"comparison":"Near","field":"subject","values":["Daily","Report"]},{"comparison":"Equals","field":"message","values":["November"]}],"nextGroupComparison":"Or"},{"comparison":"Null","fields":[{"comparison":"Equals","field":"message","values":["October"]}],"nextGroupComparison":"Null"}],"revision":0,"version":1}
On Sat, May 10, 2008 at 2:54 AM, Kiril <kir...@gm...> wrote:
> Hi all,
>
> I'm newbie to json-lib.
> I want to use it to serialize a class with a List<Class>, containing number
> of subclasses.
>
> While toJSON works fine, passing back the same string to toJava works only
> partially - the root class is generated Ok, but the children, in the List
> are MorphDynaBean's.
>
> Here is the code:
>
> JSONUtils.getMorpherRegistry().registerMorpher(new
> EnumMorpher(GroupComparison.class));
> JSONUtils.getMorpherRegistry().registerMorpher(new
> EnumMorpher(NextGroupComparison.class));
> JSONUtils.getMorpherRegistry().registerMorpher(new
> EnumMorpher(FieldComparison.class));
> JSONObject jsonObject = new JSONObject();
> JsonConfig jsonConfig = new JsonConfig();
> jsonConfig.setRootClass( Filter.class );
> jsonConfig.setEnclosedType(List.class);
> jsonObject = (JSONObject)JSONSerializer.toJSON(jsonString);
> Filter filter = (Filter)JSONSerializer.toJava(jsonObject,
> jsonConfig);
>
> The Filter class contains List of Group classes, but these are generated as
> a MorphDynaBean...
>
> Thanks in advance for any help!
>
> Kiril.
>
|