I have a JSON object like this:
{
"shippingLines": [{
"carrier": "NZ Post",
"price": {
"amount": 5.50,
"currency": "NZD"
}
}],
"taxAmount": {
"amount": 5.325,
"currency": "NZD"
},
"reference": "INV000045",
"totalAmount": {
"amount": 35.5,
"currency": "NZD"
},
"returnUrls": {
"successUrl": "http://yourserver/success",
"failUrl": "http://yourserver/fail",
"callbackUrl": "http://yourserver/fail-safe-callback"
}
}
I want to strip off all JSON formatting (spaces, comma, parentheses, brackets, quotes, colon) from it and product an output like following:
shippingLinescarrierNZPostpriceamount5.50currencyNZDtaxAmountamount5.325currencyNZDreferenceINV000045totalAmountamount35.5currencyNZDreturnUrlssuccessUrlhttp://yourserver.com/successfailUrlhttp://.yourserver.com/failcallbackUrlhttp://yourserver.com/fail-safe-callback
so I tried a bunch of replaceAll()
like below:
String json = objectMapper.writeValueAsString(<Json Class here>); // using Jackson
json.replaceAll("\"", "")
.replaceAll("\\{","")
.replaceAll("\\}","")
.replaceAll("\\[","")
.replaceAll("\\]","")
.replaceAll(":","")
.replaceAll(",","")
.replaceAll(" ","");
But this also replaced the "colon" in the URL (http://...) in the returnUrls
object.
Is there a better way to achieve this ?
Note: I'm on Java 7.