• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Convert java object to jason tree or ExtJs tree string

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .

 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Himanshu Bhatnagar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i wanted the json version of my object , so that i can pass that to extjs store and can get a visual tree
 
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try a library like Jackson to convert your object to a JSON (not "jason") string.
 
Himanshu Bhatnagar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 expects
  • Write 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
     
    Willie Smits can speak 40 languages. This tiny ad can speak only one:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic