Quantcast
Channel: JSON order mixed up - Stack Overflow
Viewing all articles
Browse latest Browse all 18

Answer by prachi for JSON order mixed up

$
0
0

For Java code, Create a POJO class for your object instead of a JSONObject.and use JSONEncapsulator for your POJO class.that way order of elements depends on the order of getter setters in your POJO class.for eg. POJO class will be like

Class myObj{String userID;String amount;String success;// getter setters in any order that you want

and where you need to send your json object in response

JSONContentEncapsulator<myObj> JSONObject = new JSONEncapsulator<myObj>("myObject");JSONObject.setObject(myObj);return Response.status(Status.OK).entity(JSONObject).build();

The response of this line will be

{myObject : {//attributes order same as getter setter order.}}


Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>