Convert JSON to Protocol Buffers
Twister pairs nicely with Jackson’s ObjectMapper
since they both use POJOs.
Convert a JSON String to Protocol Buffer Bytes
String jsonString = "{ \"id\": 1, \"name\": \"John Doe\" }";
Map<String, Object> personMap = new ObjectMapper().readValue(jsonString, Map.class);
ByteBuffer byteBuffer = new ProtoWriter().write(personMap, "Person");
Infer a Protocol Buffer Descriptor from a JSON String
String jsonString = "{\"name\": \"John Doe\", \"age\": 30, \"isStudent\": true}";
Map<String, Object> personMap = new ObjectMapper().readValue(jsonString, Map.class);
Descriptors.Descriptor descriptor = new ProtoDescriptorInferrer().infer(personMap, "Person");