This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSON Formatting with Jersey and Jackson

 
James Dekker
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • 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.
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • 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: 221
  • Mark post as helpful
  • send pies
  • 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: 642
  • Mark post as helpful
  • send pies
  • 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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic