use of com.serotonin.m2m2.i18n.TranslatableMessageParseException in project ma-core-public by MangoAutomation.
the class PointValueTimeDeserializer method deserialize.
@Override
public PointValueTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
ObjectCodec codec = jsonParser.getCodec();
JsonNode node = codec.readTree(jsonParser);
JsonNode dataTypeNode = node.get("dataType");
if (dataTypeNode == null) {
throw JsonMappingException.from(jsonParser, "Missing dataType");
}
JsonNode valueNode = node.get("value");
if (valueNode == null) {
throw JsonMappingException.from(jsonParser, "Missing value");
}
JsonNode timestampNode = node.get("timestamp");
if (timestampNode == null) {
throw JsonMappingException.from(jsonParser, "Missing timestamp");
}
long timestamp = timestampNode.asLong();
String dataTypeStr = dataTypeNode.asText();
DataType dataType = DataType.fromName(dataTypeStr);
if (dataType == null) {
throw JsonMappingException.from(jsonParser, "Unknown dataType: " + dataTypeStr);
}
DataValue dataValue;
switch(dataType) {
case ALPHANUMERIC:
dataValue = new AlphanumericValue(valueNode.asText());
break;
case BINARY:
dataValue = new BinaryValue(valueNode.asBoolean());
break;
case MULTISTATE:
dataValue = new MultistateValue(valueNode.asInt());
break;
case NUMERIC:
dataValue = new NumericValue(valueNode.asDouble());
break;
default:
throw JsonMappingException.from(jsonParser, "Unsupported dataType " + dataType);
}
JsonNode annotationNode = node.get("serializedAnnotation");
if (annotationNode != null && !annotationNode.isNull()) {
try {
return new AnnotatedPointValueTime(dataValue, timestamp, TranslatableMessage.deserialize(annotationNode.asText()));
} catch (TranslatableMessageParseException e) {
throw JsonMappingException.from(jsonParser, "Can't deserialize annotation", e);
}
}
return new PointValueTime(dataValue, timestamp);
}
use of com.serotonin.m2m2.i18n.TranslatableMessageParseException in project ma-core-public by infiniteautomation.
the class PointValueTimeDeserializer method deserialize.
@Override
public PointValueTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
ObjectCodec codec = jsonParser.getCodec();
JsonNode node = codec.readTree(jsonParser);
JsonNode dataTypeNode = node.get("dataType");
if (dataTypeNode == null) {
throw JsonMappingException.from(jsonParser, "Missing dataType");
}
JsonNode valueNode = node.get("value");
if (valueNode == null) {
throw JsonMappingException.from(jsonParser, "Missing value");
}
JsonNode timestampNode = node.get("timestamp");
if (timestampNode == null) {
throw JsonMappingException.from(jsonParser, "Missing timestamp");
}
long timestamp = timestampNode.asLong();
String dataTypeStr = dataTypeNode.asText();
DataType dataType = DataType.fromName(dataTypeStr);
if (dataType == null) {
throw JsonMappingException.from(jsonParser, "Unknown dataType: " + dataTypeStr);
}
DataValue dataValue;
switch(dataType) {
case ALPHANUMERIC:
dataValue = new AlphanumericValue(valueNode.asText());
break;
case BINARY:
dataValue = new BinaryValue(valueNode.asBoolean());
break;
case MULTISTATE:
dataValue = new MultistateValue(valueNode.asInt());
break;
case NUMERIC:
dataValue = new NumericValue(valueNode.asDouble());
break;
default:
throw JsonMappingException.from(jsonParser, "Unsupported dataType " + dataType);
}
JsonNode annotationNode = node.get("serializedAnnotation");
if (annotationNode != null && !annotationNode.isNull()) {
try {
return new AnnotatedPointValueTime(dataValue, timestamp, TranslatableMessage.deserialize(annotationNode.asText()));
} catch (TranslatableMessageParseException e) {
throw JsonMappingException.from(jsonParser, "Can't deserialize annotation", e);
}
}
return new PointValueTime(dataValue, timestamp);
}
Aggregations