Imagine a simple JSON response such as:
{
"success": false,
"message": "PEBKAC"
}
Given I have boolean and String variables, what’s the simplest way to convert them to JSON in Java, without resorting to String.format and friends.
I’m more familiar with C#, where this is quite straightforward using the built-in JavaScriptSerializer class:
var success = false;
var message = "PEBKAC";
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(new { success, message });
Is there anything this straightforward for Java?
using JSON
serialization
deserialization
using google-gson
serialization
deserialization