Skip to content

Commit

Permalink
KAFKA-12214: Generated code does not include UUID or struct fields in…
Browse files Browse the repository at this point in the history
… its toString output (#9914)

Reviewers: Justine Olshan <jolshan@confluent.io>, Ismael Juma <ismael@juma.me.uk>
  • Loading branch information
cmccabe committed Jan 16, 2021
1 parent 7ac0606 commit 06c9a39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,26 @@ private void testRoundTrip(SimpleExampleMessageData message,
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1900,9 +1900,8 @@ private void generateFieldToString(String prefix, FieldSpec field) {
} 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()) {
Expand Down

0 comments on commit 06c9a39

Please sign in to comment.