File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 613
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: 613
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
Interfaces Implementation.
father & mother class
Send PUT to different RESTful webservice running on the same local Tomcat?
ArrayList is Picking Up Last Item During Iteration.
Got null response from webservice while calling an implementation method which has arguements in it