use of org.activityinfo.legacy.shared.command.Command in project activityinfo by bedatadriven.
the class CommandDeserializer method deserialize.
@Override
public Command deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
ObjectNode root = (ObjectNode) mapper.readTree(jp);
String typeName = root.path("type").asText();
if (Strings.isNullOrEmpty(typeName)) {
throw new BadRpcRequest("Expected 'type' property on root object. You must specify a command type.");
}
Class commandClass;
try {
commandClass = lookupCommandClass(typeName);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to find command class for " + typeName, e);
throw new BadRpcRequest("Invalid command type '%s'", typeName);
}
JsonNode command = root.path("command");
if (!command.isObject()) {
throw new BadRpcRequest("Expected 'command' root object property.");
}
try {
return (Command) mapper.readValue(command, commandClass);
} catch (UnrecognizedPropertyException e) {
throw new BadRpcRequest("Unexpected property '%s'", formatPath(e.getPath()));
}
}
Aggregations