use of org.qi4j.api.type.ValueCompositeType in project qi4j-sdk by Qi4j.
the class JSONResponseReader method readResponse.
@Override
public Object readResponse(Response response, Class<?> resultType) {
if (response.getEntity().getMediaType().equals(MediaType.APPLICATION_JSON)) {
if (ValueComposite.class.isAssignableFrom(resultType)) {
String jsonValue = response.getEntityAsText();
ValueCompositeType valueType = module.valueDescriptor(resultType.getName()).valueType();
return valueDeserializer.deserialize(valueType, jsonValue);
} else if (resultType.equals(Form.class)) {
try {
String jsonValue = response.getEntityAsText();
JSONObject jsonObject = new JSONObject(jsonValue);
Iterator<?> keys = jsonObject.keys();
Form form = new Form();
while (keys.hasNext()) {
Object key = keys.next();
form.set(key.toString(), jsonObject.get(key.toString()).toString());
}
return form;
} catch (JSONException e) {
throw new ResourceException(e);
}
}
}
return null;
}
Aggregations