Friday, December 16, 2016

Converting Java object to JSON string using Gson library





Download Gson library and put in your project build path.


Java Object will be a pojo javaObject with fields status,code and message.

Code:
           
                Gson gson = new Gson();
jsonResponse = gson.toJson(javaObject);

               log.info(" json string : " + jsonResponse);


Output:

{
           "status": 200,
           "code": "007",
          "message": "working fine"
}


No comments:

Post a Comment

Fixing yum command on linux

You may find yourself having to fix more packages. So you can just remove everything you had installed via  pip and reinstall everythin...