Skip to content

Commit 5381e23

Browse files
IPROTO-218 Support uninitialized Date and Instant
1 parent 43a4f8c commit 5381e23

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

core/src/main/java/org/infinispan/protostream/annotations/impl/AbstractMarshallerCodeGenerator.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ protected String generateReadMethodBody(ProtoMessageTypeMetadata messageTypeMeta
267267
|| fieldMetadata.getProtobufType().getJavaType() == JavaType.STRING
268268
|| fieldMetadata.getProtobufType().getJavaType() == JavaType.BYTE_STRING
269269
|| fieldMetadata.getProtobufType().getJavaType() == JavaType.ENUM
270-
|| fieldMetadata.getProtobufType().getJavaType() == JavaType.MESSAGE) {
270+
|| fieldMetadata.getProtobufType().getJavaType() == JavaType.MESSAGE
271+
|| fieldMetadata.getJavaType().getCanonicalName().equals(Date.class.getCanonicalName())
272+
|| fieldMetadata.getJavaType().getCanonicalName().equals(Instant.class.getCanonicalName())) {
271273
iw.append(" = null");
272274
} else if (fieldMetadata.isPrimitive()) {
273275
if (fieldMetadata.getProtobufType() == Type.BOOL) {

core/src/test/java/org/infinispan/protostream/annotations/impl/ProtoSchemaBuilderTest.java

+28
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,12 @@ static class MessageWithAllFieldTypes {
892892
@ProtoField(number = 36, defaultValue = "36")
893893
Byte[] testField36 = {1, 2, 3};
894894

895+
@ProtoField(number = 37)
896+
Date getTestField37;
897+
898+
@ProtoField(number = 38)
899+
Instant getTestField38;
900+
895901
private char testField51;
896902

897903
@ProtoField(number = 51, defaultValue = "A")
@@ -1287,6 +1293,28 @@ public Byte[] getTestField86() {
12871293
public void setTestField86(Byte[] testField86) {
12881294
this.testField86 = testField86;
12891295
}
1296+
1297+
private Date testField87;
1298+
1299+
@ProtoField(number = 87)
1300+
public Date getTestField87() {
1301+
return testField87;
1302+
}
1303+
1304+
public void setTestField87(Date testField87) {
1305+
this.testField87 = testField87;
1306+
}
1307+
1308+
private Instant testField88;
1309+
1310+
@ProtoField(number = 88)
1311+
public Instant getTestField88() {
1312+
return testField88;
1313+
}
1314+
1315+
public void setTestField88(Instant testField88) {
1316+
this.testField88 = testField88;
1317+
}
12901318
}
12911319

12921320
@Test

processor/src/test/java/org/infinispan/protostream/annotations/impl/processor/tests/AutoProtoSchemaBuilderTest.java

+28
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ static class MessageWithAllFieldTypes {
373373
@ProtoField(number = 36, defaultValue = "36")
374374
Byte[] testField36 = {1, 2, 3};
375375

376+
@ProtoField(number = 37)
377+
Date getTestField37;
378+
379+
@ProtoField(number = 38)
380+
Instant getTestField38;
381+
376382
private char testField51;
377383

378384
@ProtoField(number = 51, defaultValue = "A")
@@ -768,6 +774,28 @@ public Byte[] getTestField86() {
768774
public void setTestField86(Byte[] testField86) {
769775
this.testField86 = testField86;
770776
}
777+
778+
private Date testField87;
779+
780+
@ProtoField(number = 87)
781+
public Date getTestField87() {
782+
return testField87;
783+
}
784+
785+
public void setTestField87(Date testField87) {
786+
this.testField87 = testField87;
787+
}
788+
789+
private Instant testField88;
790+
791+
@ProtoField(number = 88)
792+
public Instant getTestField88() {
793+
return testField88;
794+
}
795+
796+
public void setTestField88(Instant testField88) {
797+
this.testField88 = testField88;
798+
}
771799
}
772800

773801
@AutoProtoSchemaBuilder(includeClasses = MessageWithAllFieldTypes.class)

0 commit comments

Comments
 (0)