@Test
public void deserializeUnionWithUnknownFields() throws Descriptors.DescriptorValidationException {

    // Add a field to the union descriptor message so as
    // to make it possible to read an unknown field.
    final Descriptors.Descriptor biggerUnionDescriptor = addFieldToUnionDescriptor("dummy_field", DescriptorProtos.FieldDescriptorProto.Type.TYPE_BOOL);
    final DynamicMessage message1 = DynamicMessage.newBuilder(biggerUnionDescriptor)
            .setField(biggerUnionDescriptor.findFieldByName("_MySimpleRecord"), TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1066L).build())
            .setField(biggerUnionDescriptor.findFieldByName("dummy_field"), Boolean.TRUE)
            .build();
    RecordSerializationException ex1 = assertThrows(RecordSerializationException.class,
            () -> serializer.deserializeUnion(metaData.getUnionDescriptor(), Tuple.from(1066L), message1.toByteArray(), metaData.getVersion()));
    assertThat(ex1.getMessage(), containsString("Could not deserialize union message"));
    assertThat(ex1.getMessage(), containsString("there are unknown fields"));
    assertThat((Collection<?>)ex1.getLogInfo().get("unknownFields"), not(empty()));
    // Remove a field from the union descriptor and set it.
    final Descriptors.Descriptor smallerUnionDescriptor = removeFieldFromUnionDescriptor("_MySimpleRecord");
    final Message message2 = TestRecords1Proto.RecordTypeUnion.newBuilder()
            .setMySimpleRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1066L).build())
            .build();
    RecordSerializationException ex2 = assertThrows(RecordSerializationException.class,
            () -> serializer.deserializeUnion(smallerUnionDescriptor, Tuple.from(1066L), message2.toByteArray(), metaData.getVersion()));
    assertThat(ex2.getMessage(), containsString("Could not deserialize union message"));
    assertThat(ex2.getMessage(), containsString("there are unknown fields"));
    assertThat((Collection<?>)ex2.getLogInfo().get("unknownFields"), not(empty()));
}