KAFKA-12214: Generated code does not include UUID or struct fields in its toString output (#9914)

Reviewers: Justine Olshan <jolshan@confluent.io>, Ismael Juma <ismael@juma.me.uk>
This commit is contained in:
Colin Patrick McCabe 2021-01-15 16:32:55 -08:00 committed by GitHub
parent 7ac06065f1
commit 06c9a39101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -419,4 +419,26 @@ public class SimpleExampleMessageTest {
assertEquals(message.hashCode(), messageFromJson.hashCode());
}
@Test
public void testToString() {
SimpleExampleMessageData message = new SimpleExampleMessageData();
message.setMyUint16(65535);
message.setTaggedUuid(Uuid.fromString("x7D3Ck_ZRA22-dzIvu_pnQ"));
message.setMyFloat64(1.0);
assertEquals("SimpleExampleMessageData(processId=AAAAAAAAAAAAAAAAAAAAAA, " +
"myTaggedIntArray=[], " +
"myNullableString=null, " +
"myInt16=123, myFloat64=1.0, " +
"myString='', " +
"myBytes=[], " +
"taggedUuid=x7D3Ck_ZRA22-dzIvu_pnQ, " +
"taggedLong=914172222550880202, " +
"zeroCopyByteBuffer=java.nio.HeapByteBuffer[pos=0 lim=0 cap=0], " +
"nullableZeroCopyByteBuffer=java.nio.HeapByteBuffer[pos=0 lim=0 cap=0], " +
"myStruct=MyStruct(structId=0, arrayInStruct=[]), " +
"myTaggedStruct=TaggedStruct(structId=''), " +
"myCommonStruct=TestCommonStruct(foo=123, bar=123), " +
"myOtherCommonStruct=TestCommonStruct(foo=123, bar=123), " +
"myUint16=65535)", message.toString());
}
}

View File

@ -1900,9 +1900,8 @@ public final class MessageDataGenerator implements MessageClassGenerator {
} else if (field.type().isRecords()) {
buffer.printf("+ \"%s%s=\" + %s%n",
prefix, field.camelCaseName(), field.camelCaseName());
} else if (field.type().isStruct() ||
field.type() instanceof FieldType.UUIDFieldType) {
} else if (field.type().isStruct()) {
} else if (field.type() instanceof FieldType.UUIDFieldType ||
field.type().isStruct()) {
buffer.printf("+ \"%s%s=\" + %s.toString()%n",
prefix, field.camelCaseName(), field.camelCaseName());
} else if (field.type().isArray()) {