Search in sources :

Example 1 with AbstractPublisherModel

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

the class PublisherModelDeserializer method deserialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
	 */
@Override
public AbstractPublisherModel<?, ?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    String typeName = tree.get("modelType").asText();
    PublisherDefinition definition = ModuleRegistry.getPublisherDefinition(typeName);
    if (definition == null)
        throw new ModelNotFoundException(typeName);
    AbstractPublisherModel<?, ?> model = (AbstractPublisherModel<?, ?>) mapper.treeToValue(tree, definition.getPublisherModelClass());
    // Set the definition here
    model.setDefinition(definition);
    return model;
}
Also used : PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) AbstractPublisherModel(com.serotonin.m2m2.web.mvc.rest.v1.model.publisher.AbstractPublisherModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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 AbstractPublisherModel (com.serotonin.m2m2.web.mvc.rest.v1.model.publisher.AbstractPublisherModel)1