Search in sources :

Example 1 with PointLocatorModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.PointLocatorModel in project ma-core-public by infiniteautomation.

the class PointLocatorModelDeserializer method deserialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
	 */
@Override
public PointLocatorModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    if (!tree.hasNonNull("modelType"))
        throw new IOException("No modelType field found for point locator model.");
    ModelDefinition definition = findModelDefinition(tree.get("modelType").asText());
    return (PointLocatorModel<?>) mapper.treeToValue(tree, definition.getModelClass());
}
Also used : ModelDefinition(com.serotonin.m2m2.module.ModelDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) PointLocatorModel(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.PointLocatorModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ModelDefinition (com.serotonin.m2m2.module.ModelDefinition)1 PointLocatorModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.PointLocatorModel)1 IOException (java.io.IOException)1