@Override public JsonElement serialize(JsonRpcResponse src, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.addProperty(ResponseProperty.ID.key(), src.getId()); if (src.isError()) { JsonObject error = new JsonObject(); error.addProperty(ParamsProperty.MESSAGE.key(), src.getErrorMessage()); result.add(ResponseProperty.ERROR.key(), error); } else { JsonObject data = new JsonObject(); for (Entry<ParamsProperty, Object> properties : src.getData().entrySet()) { data.add(properties.getKey().key(), context.serialize(properties.getValue())); } result.add(ResponseProperty.DATA.key(), data); } return result; }