Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created July 6, 2015 20:20
Show Gist options
  • Save frsyuki/eda7895b4a3172222d95 to your computer and use it in GitHub Desktop.
Save frsyuki/eda7895b4a3172222d95 to your computer and use it in GitHub Desktop.
@MessagePackDeserializer(PlanNodeDeserializer.class)
public abstract class PlanNode
{
...
}
public class PlanNodeDeserializer extends Deserializer<PlanNode>
{
public PlanNode deserialize(Unpacker unpacker)
{
Value value = unpacker.unpackValue();
if (value.asMap().map().get("error") != null) {
return new ObjectMapper().readValue(value, ErrorNode.class);
} else if (value.asMap().map().get("engine") != null) {
return new ObjectMapper().readValue(value, EngineNode.class);
} else {
throw new MessageTypeException("unknown type");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment