Hi All,=0AI have a complicated JSON string which i am trying to serialize t=
o Java Objects using the Json-Lib library.=0AI thought i will post a code s=
nippet here to know if i am doing the right thing or theres a simpler way t=
o serialize json to java.=0ACalling JSONObject.toBean() returns a bunch of =
MorphDynaBeans which i morph to the objects in my application using EZMorph=
library.=0APlease have a look and send in your comments.=0A=0AThis is my J=
SON string=0A{=0A"name":"Nameless One",=0A"pages":[=0A{"name":"Page1",=0A"c=
anvas":"{"objectType":"EditorCanvas",=0A"id":"editorCanvas",=0A"name":"",=
=0A"sizeWidth":940,=0A"cssClass":"",=0A"style":"width:940px;",=0A"children"=
:[=0A{"objectType":"TextObject",=0A"id":"Text_1196907790312",=0A"name":"",=
=0A"cssClass":"",=0A"style":"left:40px;top:60px;width:620px;height:100px;",=
=0A"text":""[Winning the Nobel Peace Prize] ." =97Mohammad Yunus"},=0A{"obj=
ectType":"ImageObject",=0A"id":"Image_1196907800312",=0A"name":"",=0A"posit=
ion":({left:40, top:220}),=0A"size":({width:300, height:300}),=0A"cssClass"=
:"",=0A"style":"left:40px;top:220px;width:300px;height:300px;",=0A}=0A]=0A}=
"=0A}=0A]=0A}=0A=0AJSON json =3D JSONSerializer.toJSON(jsonStr);=0A=0AMorph=
erRegistry morpherRegistry =3D new MorpherRegistry();=0AmorpherRegistry.reg=
isterMorpher( new BeanMorpher( BaseObject.class,morpherRegistry));=0Amorphe=
rRegistry.registerMorpher( new BeanMorpher(SplashNoteObject.class, morpherR=
egistry));=0AmorpherRegistry.registerMorpher( new BeanMorpher( PageObject.c=
lass,morpherRegistry));=0AmorpherRegistry.registerMorpher( new BeanMorpher(=
EditorCanvas.class, morpherRegistry));=0A=0ASplashNoteObject snObject =3D (=
SplashNoteObject) JSONObject.toBean((JSONObject) json, SplashNoteObject.cla=
ss );=0APageObject page =3D(PageObject)morpherRegistry.morph(PageObject.cla=
ss,snObject.getPages().get(0));=0A=0AEditorCanvas bean =3D (EditorCanvas)pa=
ge.getCanvas();=0A=0Ai havent included the code for any further levels like=
TextObject and ImageObject=0A=0AIs this the only was i can serialize json =
to java for java objects which have other java objects in them. Do i need=
=0Ato morph the objects at every level to the bean i need.=0A=0ACheers=0AHa=
ritha=0A=0A=0A=0A=0A _________________________________________________=
___________________________________=0ANever miss a thing. Make Yahoo your =
home page. =0Ahttp://www.yahoo.com/r/hs |