Using Java 6, Tomcat 7, Jersey 1.15, Jackson 2.0.6 (from FasterXml maven repo), & Google GSON 2.2.2,
I am trying to pretty print the JSON String so it will look indented by the curl -X GET command line.
I 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:
My web service:
When I run this using:
I get this in my Eclipse's console (which is exactly what I want):
But from the command line curl command listed above, I get this
(there are 4 spaces after \n but JavaRanch's forum doesn't show it):
How can I make the JSON formatting to be identical to what I am getting in Eclipse's console by using the curl command?
This is similar to my other two posts, located using Jackson and Using json.org/java. The only reason I am posting using all 3 parsers is because I want to help other people with similar problems who are using a specific JSON library of choice, in the future.
its not required to club Jackson and Gson. though I was not able to reproduce the problem you seeing by mixing it. I am just using following code
may be something to do with the way your OS is treating it, I am using cgywin on windows and get following output
All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Joined: Dec 09, 2006
It still didn't work on Linux... Thank you for your help, nonetheless.
Joined: Feb 10, 2001
yeha, I as mention its to do with OS, as webservice is corrently adding \n to the ouput along with indentation. so you may want to capture the output of webservice in variable and echo it using -e.
when i tried this
I get output as is, but adding -e to echo i.e echo -e ... I get the formatted output.
Of course I am trying on cywin as I don't have Linux.