ProtoMapper extends AbstractProtoMapper { @Override public Object fromProto(Value any) { switch (any.getKindCase()) { case NULL_VALUE: return null; case BOOL_VALUE: return any.getBoolValue(); case NUMBER_VALUE: return any.getNumberValue(); case STRING_VALUE: return any.getStringValue(); case STRUCT_VALUE: Struct struct = any.getStructValue(); Map<String, Object> map = new HashMap<>(); for (Map.Entry<String, Value> pair : struct.getFieldsMap().entrySet()) { map.put(pair.getKey(), fromProto(pair.getValue())); } return map; case LIST_VALUE: List<Object> list = new ArrayList<>(); for (Value val : any.getListValue().getValuesList()) { list.add(fromProto(val)); } return list; default: throw new ClassCastException("unset Value element: "+any); } } private  ProtoMapper(); @Override Value toProto(Object val); @Override Object fromProto(Value any); @Override List<WorkflowTask> fromProto(WorkflowTaskPb.WorkflowTask.WorkflowTaskList list); @Override WorkflowTaskPb.WorkflowTask toProto(final WorkflowTask from); @Override WorkflowTask fromProto(final WorkflowTaskPb.WorkflowTask from); @Override WorkflowTaskPb.WorkflowTask.WorkflowTaskList toProto(List<WorkflowTask> list); @Override Any toProto(Any in); @Override Any fromProto(Any in); static final ProtoMapper INSTANCE; }
@Test public void workflowTaskFromProto() { final WorkflowTaskPb.WorkflowTask taskWithDefaultRetryCount = WorkflowTaskPb.WorkflowTask.newBuilder().build(); final WorkflowTaskPb.WorkflowTask taskWith1RetryCount = WorkflowTaskPb.WorkflowTask.newBuilder().setRetryCount(1).build(); final WorkflowTaskPb.WorkflowTask taskWithNoRetryCount = WorkflowTaskPb.WorkflowTask.newBuilder().setRetryCount(-1).build(); assertEquals(new Integer(0), mapper.fromProto(taskWithDefaultRetryCount).getRetryCount()); assertEquals(1, mapper.fromProto(taskWith1RetryCount).getRetryCount().intValue()); assertNull(mapper.fromProto(taskWithNoRetryCount).getRetryCount()); }