Reference Guide

Table Of Contents
return device;
}
@Override
public ObjectNode encode(Switch device) {
ObjectNode node = mapper.createObjectNode();
node.put(MAC_ADDRESS, device.getMacAddress().toString());
if (device.getId() != null) {
node.put(ID, device.getId().getValue().longValue());
}
if (device.getIpAddress() != null) {
node.put(IP_ADDRESS, device.getIpAddress().toString());
}
if (device.getFriendlyName() != null) {
node.put(FRIENDLY_NAME, device.getFriendlyName());
}
if (device.getActiveState() != null) {
node.put(ACTIVE_STATE, device.getActiveState().name());
}
return node;
}
private static void validateMandatoryFields(ObjectNode node,
String... fields) throws IllegalArgumentException {
if (fields != null) {
for (String field : fields) {
if (node.path(field).isMissingNode()) {
throw new IllegalArgumentException("JSON node '" + node
+ "' is missing field '" + field + "'");
}
}
}
}
}
There are some dependencies to declare in order to implement the codecs. Open the hm-
rs/pom.xml file and add the XML extract from the JSON Module Dependencies listing to the
<dependencies> node; after updating the POM file update the Eclipse project dependencies (see
Updating Project Dependencies on page 146).
185