jQuery in Action, 2nd edition*
The moose likes Web Services and the fly likes JSON Formatting with Jersey and Jackson Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JSON Formatting with Jersey and Jackson" Watch "JSON Formatting with Jersey and Jackson" New topic
Author

JSON Formatting with Jersey and Jackson

James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
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

Joined: Feb 10, 2001
Posts: 614
have you tried any json libraries ?

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

-P


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
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

Joined: Feb 10, 2001
Posts: 614
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: JSON Formatting with Jersey and Jackson
 
Similar Threads
Got null response from webservice while calling an implementation method which has arguements in it
father & mother class
Interfaces Implementation.
ArrayList is Picking Up Last Item During Iteration.
Send PUT to different RESTful webservice running on the same local Tomcat?