| Author |
Convert java object to jason tree or ExtJs tree string
|
Himanshu Bhatnagar
Greenhorn
Joined: Sep 27, 2011
Posts: 9
|
|
Hi,
i have a class called zone , which can have object list of zones themself . so basically a tree kind of object
how i can covert/map this java object to jason string representation of tree .
Is there some api that thake java object and ouput a jason tree string .
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
Himanshu Bhatnagar wrote:Hi,
i have a class called zone , which can have object list of zones themself . so basically a tree kind of object
how i can covert/map this java object to jason string representation of tree .
Is there some api that thake java object and ouput a jason tree string .
please be clear what you are trying to achieve ?
do you want to serialize your object to json ?
|
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
|
 |
Himanshu Bhatnagar
Greenhorn
Joined: Sep 27, 2011
Posts: 9
|
|
|
Actually i wanted the json version of my object , so that i can pass that to extjs store and can get a visual tree
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Try a library like Jackson to convert your object to a JSON (not "jason") string.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Himanshu Bhatnagar
Greenhorn
Joined: Sep 27, 2011
Posts: 9
|
|
Actually i am using gson to convert the java objects to json format and i am getting below format :
But i wanted this format for Ext js:
That is the tag called "Children :" should come
|
 |
Ted Young
Greenhorn
Joined: Aug 10, 2004
Posts: 6
|
|
I think you have two choices to get the JSON that you need to work with ExtJS:
Change your Java object model to better match what ExtJS expectsWrite a custom Serializer (or the preferred TypeAdapter) to output the JSON that you need
I'd recommend #1 if you can do it, i.e., if you have control over the classes on the server-side. Otherwise the JSON that you need for ExtJS is different enough from your object model that you'll need to write a custom "type adapter" to change how Gson serializes your objects. See http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/TypeAdapter.html for the details.
;ted
--
Ted M. Young
Read my new book: The Jackson Cookbook: JSON Recipes in Java
http://about.me/tedmyoung
|
 |
 |
|
|
subject: Convert java object to jason tree or ExtJs tree string
|
|
|