Code example for JsonObject

Methods: addProperty

0
import com.google.gson.JsonElement; 
import com.google.gson.JsonObject; 
import com.google.gson.JsonSerializationContext; 
import com.google.gson.JsonSerializer; 
 
public class ResponseObjectTypeAdapter implements JsonSerializer<ResponseObject> {
    public static final Logger s_logger = Logger.getLogger(ResponseObjectTypeAdapter.class.getName());
 
    @Override 
    public JsonElement serialize(ResponseObject responseObj, Type typeOfResponseObj, JsonSerializationContext ctx) {
        JsonObject obj = new JsonObject();
 
        if (responseObj instanceof SuccessResponse) {
            obj.addProperty("success", ((SuccessResponse) responseObj).getSuccess());
            return obj;
        } else if (responseObj instanceof ExceptionResponse) {
            obj.addProperty("errorcode", ((ExceptionResponse) responseObj).getErrorCode());
            obj.addProperty("errortext", ((ExceptionResponse) responseObj).getErrorText());
            return obj;
        } else {