• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSON Formatting with Jersey and Jackson

 
Ranch Hand
Posts: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Java 6, Tomcat 7, Jersey 1.15, Jackson 1.9.9, created a simple web service which has the following architecture:

My POJOs (model classes):





Using a Utility Class, I decided to hard code the POJOs as follows:



MyWebService:



Produces:


What I need to do is have it produce it in a more legible manner:



Just am seeking a way to implement so it can display some type of formatting with indentation / tabs.

Would be very grateful if someone could assist me.

Thank you for taking the time to read this.
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you tried any json libraries ?

1) googles json lib
2) JSON try toString method from this lib.

-P
 
James Dekker
Ranch Hand
Posts: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Praful,

Thanks for the response!

When I tried this:



Using the curl command in Linux (this is my actual web service client):



This is the response I got:

{"children":[{"age":"12","gender":"male","name":"Jimmy"}],"father":"Joe","mother":"Jennifer"}

Doesn't seem like anything happened...

Here are the dependencies listed in my pom.xml file:



Does anyone know what I am possibly doing wrong?
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not used fasterxml.jackson so no idea about it, try this





NOTE:- Retrun Type is String now
I get following output



Also, are you sure you paste correct code? I checked the online API of fasterxml and there is nothing like SerializationConfig.Feature.INDENT, it is SerializationConfigFeature.INDENT

-P

 
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic