use of net.sf.mbus4j.SerialPortConnection in project ma-modules-public by infiniteautomation.
the class MBusConnectionDeserializer method deserialize.
/* (non-Javadoc)
* @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
*/
@Override
public Connection deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode n = p.readValueAsTree();
JsonNode t = n.get("modelType");
int bitPerSecond = n.get("bitPerSecond").asInt();
int responseTimeoutOffset = n.get("responseTimeoutOffset").asInt();
String type = null;
if (t != null)
type = t.asText();
else
throw new IOException("No connection model type provided.");
switch(type) {
case "mbusSerial":
SerialPortConnection serialModel = new SerialPortConnection(n.get("portName").asText(), bitPerSecond, responseTimeoutOffset);
return serialModel;
case "mbusTcpIp":
TcpIpConnection tcpModel = new TcpIpConnection(n.get("host").asText(), n.get("port").asInt(), bitPerSecond, responseTimeoutOffset);
return tcpModel;
default:
throw new IOException("Invalid model type: " + type);
}
}
Aggregations