use of com.serotonin.m2m2.web.mvc.rest.v1.model.email.UserEntryModel in project ma-modules-public by infiniteautomation.
the class EmailRecipientModelDeserializer method deserialize.
/* (non-Javadoc)
* @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
*/
@Override
public EmailRecipientModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode tree = jp.readValueAsTree();
String type = tree.get("type").asText();
int code = EmailRecipient.TYPE_CODES.getId(type);
switch(code) {
case EmailRecipient.TYPE_ADDRESS:
return (AddressEntryModel) mapper.treeToValue(tree, AddressEntryModel.class);
case EmailRecipient.TYPE_MAILING_LIST:
return (MailingListModel) mapper.treeToValue(tree, MailingListModel.class);
case EmailRecipient.TYPE_USER:
return (UserEntryModel) mapper.treeToValue(tree, UserEntryModel.class);
default:
throw new ModelNotFoundException(type);
}
}
Aggregations