public JSONObject toJson(Object representation) {
if (representation == null) {
return null;
}
BaseResourceRepresentation baseRepresentation = (BaseResourceRepresentation) representation;
JSONObject json = new JSONObject();
basePropertiesToJson(baseRepresentation, json);
instanceToJson(baseRepresentation, json);
extraPropertiesToJson(baseRepresentation, json);
return json;