Search in sources :

Example 1 with ResponseBodyException

use of io.crnk.client.ResponseBodyException in project crnk-framework by crnk-project.

the class ClientResourceUpsert method setLinks.

protected void setLinks(Resource dataBody, Object instance, ResourceInformation resourceInformation) {
    ResourceField linksField = resourceInformation.getLinksField();
    if (dataBody.getLinks() != null && linksField != null) {
        JsonNode linksNode = dataBody.getLinks();
        Class<?> linksClass = linksField.getType();
        ObjectReader linksMapper = objectMapper.readerFor(linksClass);
        try {
            Object links = linksMapper.readValue(linksNode);
            linksField.getAccessor().setValue(instance, links);
        } catch (IOException e) {
            throw new ResponseBodyException("failed to parse links information", e);
        }
    }
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ResponseBodyException(io.crnk.client.ResponseBodyException)

Example 2 with ResponseBodyException

use of io.crnk.client.ResponseBodyException in project crnk-framework by crnk-project.

the class ClientResourceUpsert method setMeta.

protected void setMeta(Resource dataBody, Object instance, ResourceInformation resourceInformation) {
    ResourceField metaField = resourceInformation.getMetaField();
    if (dataBody.getMeta() != null && metaField != null) {
        JsonNode metaNode = dataBody.getMeta();
        Class<?> metaClass = metaField.getType();
        ObjectReader metaMapper = objectMapper.readerFor(metaClass);
        try {
            Object meta = metaMapper.readValue(metaNode);
            metaField.getAccessor().setValue(instance, meta);
        } catch (IOException e) {
            throw new ResponseBodyException("failed to parse links information", e);
        }
    }
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ResponseBodyException(io.crnk.client.ResponseBodyException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)2 ResponseBodyException (io.crnk.client.ResponseBodyException)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)2 IOException (java.io.IOException)2