Search in sources :

Example 1 with TestCustomJsonName

use of com.google.protobuf.util.JsonTestProto.TestCustomJsonName in project curiostack by curioswitch.

the class MessageMarshallerTest method customJsonName.

@Test
public void customJsonName() throws Exception {
    TestCustomJsonName message = TestCustomJsonName.newBuilder().setValue(12345).build();
    assertMatchesUpstream(message);
}
Also used : TestCustomJsonName(com.google.protobuf.util.JsonTestProto.TestCustomJsonName) Test(org.junit.Test)

Example 2 with TestCustomJsonName

use of com.google.protobuf.util.JsonTestProto.TestCustomJsonName in project curiostack by curioswitch.

the class MessageMarshallerTest method preservingProtoFieldNames.

@Test
public void preservingProtoFieldNames() throws Exception {
    TestAllTypes message = TestAllTypes.newBuilder().setOptionalInt32(12345).build();
    assertMatchesUpstream(message);
    assertMatchesUpstream(message, false, true, false);
    // The json_name field option is ignored when configured to use original proto field names.
    TestCustomJsonName messageWithCustomJsonName = TestCustomJsonName.newBuilder().setValue(12345).build();
    assertMatchesUpstream(message, false, true, false);
    // Parsers accept both original proto field names and lowerCamelCase names.
    TestAllTypes.Builder builder = TestAllTypes.newBuilder();
    mergeFromJson("{\"optionalInt32\": 12345}", builder);
    assertEquals(12345, builder.getOptionalInt32());
    builder.clear();
    mergeFromJson("{\"optional_int32\": 54321}", builder);
    assertEquals(54321, builder.getOptionalInt32());
}
Also used : TestCustomJsonName(com.google.protobuf.util.JsonTestProto.TestCustomJsonName) TestAllTypes(com.google.protobuf.util.JsonTestProto.TestAllTypes) Test(org.junit.Test)

Aggregations

TestCustomJsonName (com.google.protobuf.util.JsonTestProto.TestCustomJsonName)2 Test (org.junit.Test)2 TestAllTypes (com.google.protobuf.util.JsonTestProto.TestAllTypes)1