Search in sources :

Example 1 with NullValue

use of com.google.protobuf.NullValue in project curiostack by curioswitch.

the class MessageMarshallerTest method anyInMaps.

@Test
public void anyInMaps() throws Exception {
    TestAny.Builder testAny = TestAny.newBuilder();
    testAny.putAnyMap("int32_wrapper", Any.pack(Int32Value.newBuilder().setValue(123).build()));
    testAny.putAnyMap("int64_wrapper", Any.pack(Int64Value.newBuilder().setValue(456).build()));
    testAny.putAnyMap("timestamp", Any.pack(Timestamps.parse("1969-12-31T23:59:59Z")));
    testAny.putAnyMap("duration", Any.pack(Durations.parse("12345.1s")));
    testAny.putAnyMap("field_mask", Any.pack(FieldMaskUtil.fromString("foo.bar,baz")));
    Value numberValue = Value.newBuilder().setNumberValue(1.125).build();
    Struct.Builder struct = Struct.newBuilder();
    struct.putFields("number", numberValue);
    testAny.putAnyMap("struct", Any.pack(struct.build()));
    Value nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
    testAny.putAnyMap("list_value", Any.pack(ListValue.newBuilder().addValues(numberValue).addValues(nullValue).build()));
    testAny.putAnyMap("number_value", Any.pack(numberValue));
    testAny.putAnyMap("any_value_number", Any.pack(Any.pack(numberValue)));
    testAny.putAnyMap("any_value_default", Any.pack(Any.getDefaultInstance()));
    testAny.putAnyMap("default", Any.getDefaultInstance());
    assertMatchesUpstream(testAny.build(), TestAllTypes.getDefaultInstance());
}
Also used : TestAny(com.google.protobuf.util.JsonTestProto.TestAny) StringValue(com.google.protobuf.StringValue) NullValue(com.google.protobuf.NullValue) FloatValue(com.google.protobuf.FloatValue) BytesValue(com.google.protobuf.BytesValue) ListValue(com.google.protobuf.ListValue) Int64Value(com.google.protobuf.Int64Value) BoolValue(com.google.protobuf.BoolValue) UInt64Value(com.google.protobuf.UInt64Value) Value(com.google.protobuf.Value) DoubleValue(com.google.protobuf.DoubleValue) Int32Value(com.google.protobuf.Int32Value) UInt32Value(com.google.protobuf.UInt32Value) Struct(com.google.protobuf.Struct) TestStruct(com.google.protobuf.util.JsonTestProto.TestStruct) Test(org.junit.Test)

Aggregations

BoolValue (com.google.protobuf.BoolValue)1 BytesValue (com.google.protobuf.BytesValue)1 DoubleValue (com.google.protobuf.DoubleValue)1 FloatValue (com.google.protobuf.FloatValue)1 Int32Value (com.google.protobuf.Int32Value)1 Int64Value (com.google.protobuf.Int64Value)1 ListValue (com.google.protobuf.ListValue)1 NullValue (com.google.protobuf.NullValue)1 StringValue (com.google.protobuf.StringValue)1 Struct (com.google.protobuf.Struct)1 UInt32Value (com.google.protobuf.UInt32Value)1 UInt64Value (com.google.protobuf.UInt64Value)1 Value (com.google.protobuf.Value)1 TestAny (com.google.protobuf.util.JsonTestProto.TestAny)1 TestStruct (com.google.protobuf.util.JsonTestProto.TestStruct)1 Test (org.junit.Test)1