Search in sources :

Example 1 with AbstractPublishedPointModel

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

the class PublishedPointModelDeserializer method deserialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
	 */
@Override
public AbstractPublishedPointModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    // Get the model type which is of the form PUB-POINT-{publisher type name}
    String typeName = tree.get("modelType").asText();
    if (typeName != null)
        typeName = typeName.split("PUB-POINT-")[1];
    PublisherDefinition definition = ModuleRegistry.getPublisherDefinition(typeName);
    if (definition == null)
        throw new ModelNotFoundException("PUB-POINT-" + typeName);
    return (AbstractPublishedPointModel<?>) mapper.treeToValue(tree, definition.getPublishedPointModelClass());
}
Also used : PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractPublishedPointModel(com.serotonin.m2m2.web.mvc.rest.v1.model.publisher.AbstractPublishedPointModel)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PublisherDefinition (com.serotonin.m2m2.module.PublisherDefinition)1 ModelNotFoundException (com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException)1 AbstractPublishedPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.publisher.AbstractPublishedPointModel)1