From 71620068744beff5ce37781c174f68dfab51e514 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Fri, 1 Dec 2023 14:51:09 +0100 Subject: [PATCH] DataObjectInfo should not throw NPE when it is not serializable --- .../io/vertx/codegen/type/DataObjectInfo.java | 8 +++++++- .../io/vertx/test/codegen/DataObjectTest.java | 15 +++++++++++++++ .../codegen/testdataobject/BufferHolder.java | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 vertx-codegen-processor/src/test/java/io/vertx/test/codegen/testdataobject/BufferHolder.java diff --git a/vertx-codegen-processor/src/main/java/io/vertx/codegen/type/DataObjectInfo.java b/vertx-codegen-processor/src/main/java/io/vertx/codegen/type/DataObjectInfo.java index 4172b3794..25d837e3a 100644 --- a/vertx-codegen-processor/src/main/java/io/vertx/codegen/type/DataObjectInfo.java +++ b/vertx-codegen-processor/src/main/java/io/vertx/codegen/type/DataObjectInfo.java @@ -25,7 +25,13 @@ public boolean isAnnotated() { } public TypeInfo getJsonType() { - return deserializer != null ? deserializer.getJsonType() : serializer.getJsonType(); + if (deserializer != null) { + return deserializer.getJsonType(); + } else if (serializer != null) { + return serializer.getJsonType(); + } else { + return null; + } } public MapperInfo getSerializer() { diff --git a/vertx-codegen-processor/src/test/java/io/vertx/test/codegen/DataObjectTest.java b/vertx-codegen-processor/src/test/java/io/vertx/test/codegen/DataObjectTest.java index a5421a8e4..6ae37313f 100644 --- a/vertx-codegen-processor/src/test/java/io/vertx/test/codegen/DataObjectTest.java +++ b/vertx-codegen-processor/src/test/java/io/vertx/test/codegen/DataObjectTest.java @@ -8,6 +8,7 @@ import io.vertx.codegen.annotations.VertxGen; import io.vertx.codegen.doc.Doc; import io.vertx.codegen.type.*; +import io.vertx.core.buffer.Buffer; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.test.codegen.annotations.EmptyAnnotation; @@ -951,4 +952,18 @@ private void assertInvalidDataObject(Class dataObjectClass) throws Exception } catch (GenException ignore) { } } + + @Test + public void testBuffer() throws Exception { + DataObjectModel model = new GeneratorHelper() + .generateDataObject(BufferHolder.class); + assertNotNull(model); + assertTrue(model.isClass()); + + PropertyInfo prop = model.getPropertyMap().get("buffer"); + assertNotNull(prop); + assertFalse(prop.getType().getDataObject().isDeserializable()); + assertFalse(prop.getType().getDataObject().isSerializable()); + assertNull(prop.getType().getDataObject().getJsonType()); + } } diff --git a/vertx-codegen-processor/src/test/java/io/vertx/test/codegen/testdataobject/BufferHolder.java b/vertx-codegen-processor/src/test/java/io/vertx/test/codegen/testdataobject/BufferHolder.java new file mode 100644 index 000000000..c8a47641b --- /dev/null +++ b/vertx-codegen-processor/src/test/java/io/vertx/test/codegen/testdataobject/BufferHolder.java @@ -0,0 +1,18 @@ +package io.vertx.test.codegen.testdataobject; + +import io.vertx.codegen.annotations.DataObject; +import io.vertx.core.buffer.Buffer; + +@DataObject +public class BufferHolder { + + private Buffer buffer; + + public Buffer getBuffer() { + return buffer; + } + + public void setBuffer(Buffer buffer) { + this.buffer = buffer; + } +}