@Test public void testRecordToJson() throws Exception { DynamicMessage.Builder builder = recordSchema.newMessageBuilder(); Descriptor desc = builder.getDescriptorForType(); FieldDescriptor fd = desc.findFieldByName("test_string"); builder.setField(fd, "string"); fd = desc.findFieldByName("test_bool"); builder.setField(fd, true); fd = desc.findFieldByName("test_bytes"); builder.setField(fd, ByteString.copyFromUtf8("hello")); fd = desc.findFieldByName("test_double"); builder.setField(fd, 800.25); fd = desc.findFieldByName("test_float"); builder.setField(fd, 23.4f); fd = desc.findFieldByName("test_fixed32"); builder.setField(fd, 32); fd = desc.findFieldByName("test_fixed64"); builder.setField(fd, 64L); fd = desc.findFieldByName("test_int32"); builder.setField(fd, 32); fd = desc.findFieldByName("test_int64"); builder.setField(fd, 64L); fd = desc.findFieldByName("test_sfixed32"); builder.setField(fd, 32); fd = desc.findFieldByName("test_sfixed64"); builder.setField(fd, 64L); fd = desc.findFieldByName("test_sint32"); builder.setField(fd, 32); fd = desc.findFieldByName("test_sint64"); builder.setField(fd, 64L); fd = desc.findFieldByName("test_uint32"); builder.setField(fd, 32); fd = desc.findFieldByName("test_uint64"); builder.setField(fd, 64L); DynamicMessage message = builder.build(); JsonNode result = objectMapper.readTree(ProtobufSchemaUtils.toJson(message)); assertTrue(result.isObject()); assertTrue(result.get("test_str").isTextual()); assertEquals("string", result.get("test_str").textValue()); assertTrue(result.get("testBool").isBoolean()); assertEquals(true, result.get("testBool").booleanValue()); assertTrue(result.get("testBytes").isTextual()); assertEquals("aGVsbG8=", result.get("testBytes").textValue()); assertTrue(result.get("testDouble").isDouble()); assertEquals(800.25, result.get("testDouble").doubleValue(), 0.01); assertTrue(result.get("testFloat").isDouble()); assertEquals(23.4f, result.get("testFloat").doubleValue(), 0.1); assertTrue(result.get("testFixed32").isInt()); assertEquals(32, result.get("testFixed32").intValue()); assertTrue(result.get("testFixed64").isTextual()); assertEquals("64", result.get("testFixed64").textValue()); assertTrue(result.get("testInt32").isInt()); assertEquals(32, result.get("testInt32").intValue()); assertTrue(result.get("testInt64").isTextual()); assertEquals("64", result.get("testInt64").textValue()); assertTrue(result.get("testSfixed32").isInt()); assertEquals(32, result.get("testSfixed32").intValue()); assertTrue(result.get("testSfixed64").isTextual()); assertEquals("64", result.get("testSfixed64").textValue()); assertTrue(result.get("testSint32").isInt()); assertEquals(32, result.get("testSint32").intValue()); assertTrue(result.get("testSint64").isTextual()); assertEquals("64", result.get("testSint64").textValue()); assertTrue(result.get("testUint32").isInt()); assertEquals(32, result.get("testUint32").intValue()); assertTrue(result.get("testUint64").isTextual()); assertEquals("64", result.get("testUint64").textValue()); }
public DynamicMessage.Builder newMessageBuilder() { return newMessageBuilder(name()); }
ProtobufSchema implements ParsedSchema { public DynamicMessage.Builder newMessageBuilder() { return newMessageBuilder(name()); } }
ProtobufSchema implements ParsedSchema { public DynamicMessage.Builder newMessageBuilder() { return newMessageBuilder(name()); } ProtobufSchema(String schemaString);  ProtobufSchema(
      String schemaString,
      List<SchemaReference> references,
      Map<String, String> resolvedReferences,
      Integer version,
      String name
  );  ProtobufSchema(
      ProtoFileElement protoFileElement,
      List<SchemaReference> references,
      Map<String, ProtoFileElement> dependencies
  );  ProtobufSchema(Descriptor descriptor); private  ProtobufSchema(
      ProtoFileElement schemaObj,
      Integer version,
      String name,
      List<SchemaReference> references,
      Map<String, ProtoFileElement> dependencies,
      String canonicalString,
      DynamicSchema dynamicSchema,
      Descriptor descriptor
  ); }
ProtobufSchema implements ParsedSchema { public DynamicMessage.Builder newMessageBuilder() { return newMessageBuilder(name()); } ProtobufSchema(String schemaString);  ProtobufSchema(
      String schemaString,
      List<SchemaReference> references,
      Map<String, String> resolvedReferences,
      Integer version,
      String name
  );  ProtobufSchema(
      ProtoFileElement protoFileElement,
      List<SchemaReference> references,
      Map<String, ProtoFileElement> dependencies
  );  ProtobufSchema(Descriptor descriptor); private  ProtobufSchema(
      ProtoFileElement schemaObj,
      Integer version,
      String name,
      List<SchemaReference> references,
      Map<String, ProtoFileElement> dependencies,
      String canonicalString,
      DynamicSchema dynamicSchema,
      Descriptor descriptor
  ); ProtobufSchema copy(); ProtobufSchema copy(Integer version); ProtobufSchema copy(String name); ProtobufSchema copy(List<SchemaReference> references); Descriptor toDescriptor(); Descriptor toDescriptor(String name); DynamicMessage.Builder newMessageBuilder(); DynamicMessage.Builder newMessageBuilder(String name); Descriptors.EnumValueDescriptor getEnumValue(String enumTypeName, int enumNumber); static Optional<OptionElement> findOption(String name, List<OptionElement> options); @Override ProtoFileElement rawSchema(); @Override String schemaType(); @Override String name(); @Override String canonicalString(); @Override String formattedString(String format); Integer version(); @Override List<SchemaReference> references(); Map<String, String> resolvedReferences(); Map<String, ProtoFileElement> dependencies(); @Override void validate(); @Override List<String> isBackwardCompatible(ParsedSchema previousSchema); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); String fullName(); MessageIndexes toMessageIndexes(String name); String toMessageName(MessageIndexes indexes); static String toMapEntry(String s); static String toMapField(String s); }
ProtobufSchema implements ParsedSchema { public DynamicMessage.Builder newMessageBuilder() { return newMessageBuilder(name()); } ProtobufSchema(String schemaString);  ProtobufSchema(
      String schemaString,
      List<SchemaReference> references,
      Map<String, String> resolvedReferences,
      Integer version,
      String name
  );  ProtobufSchema(
      ProtoFileElement protoFileElement,
      List<SchemaReference> references,
      Map<String, ProtoFileElement> dependencies
  );  ProtobufSchema(Descriptor descriptor); private  ProtobufSchema(
      ProtoFileElement schemaObj,
      Integer version,
      String name,
      List<SchemaReference> references,
      Map<String, ProtoFileElement> dependencies,
      String canonicalString,
      DynamicSchema dynamicSchema,
      Descriptor descriptor
  ); ProtobufSchema copy(); ProtobufSchema copy(Integer version); ProtobufSchema copy(String name); ProtobufSchema copy(List<SchemaReference> references); Descriptor toDescriptor(); Descriptor toDescriptor(String name); DynamicMessage.Builder newMessageBuilder(); DynamicMessage.Builder newMessageBuilder(String name); Descriptors.EnumValueDescriptor getEnumValue(String enumTypeName, int enumNumber); static Optional<OptionElement> findOption(String name, List<OptionElement> options); @Override ProtoFileElement rawSchema(); @Override String schemaType(); @Override String name(); @Override String canonicalString(); @Override String formattedString(String format); Integer version(); @Override List<SchemaReference> references(); Map<String, String> resolvedReferences(); Map<String, ProtoFileElement> dependencies(); @Override void validate(); @Override List<String> isBackwardCompatible(ParsedSchema previousSchema); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); String fullName(); MessageIndexes toMessageIndexes(String name); String toMessageName(MessageIndexes indexes); static String toMapEntry(String s); static String toMapField(String s); static final String TYPE; static final String SERIALIZED_FORMAT; static final String PROTO2; static final String PROTO3; static final String DEFAULT_NAME; static final String MAP_ENTRY_SUFFIX; static final String KEY_FIELD; static final String VALUE_FIELD; static final Location DEFAULT_LOCATION; }