From 5ac6c8a60455d32ef40889669857bcbeec56e1bb Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:41:48 +0100 Subject: [PATCH] [Fix #3436] Ignoring unknown properties (#3437) * [Fix #3436] Ignoring unknown properties * [Fix #3436] Adding unit test --- addons/common/marshallers/avro/pom.xml | 26 ++++++++++++++++++- .../org/kie/kogito/event/avro/AvroIO.java | 1 + .../marshallers/avro/src/test/avro/pojo.avsc | 18 +++++++++++++ .../avro/AvroMarshallUnmarshallTest.java | 5 ++++ kogito-build/kogito-dependencies-bom/pom.xml | 8 +++++- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 addons/common/marshallers/avro/src/test/avro/pojo.avsc diff --git a/addons/common/marshallers/avro/pom.xml b/addons/common/marshallers/avro/pom.xml index 130f76a6d35..92bcb8017e2 100644 --- a/addons/common/marshallers/avro/pom.xml +++ b/addons/common/marshallers/avro/pom.xml @@ -72,5 +72,29 @@ - + + + + + org.apache.avro + avro-maven-plugin + ${version.org.apache.avro} + + + generate-test-sources + + schema + + + ${project.basedir}/src/test/avro/ + PRIVATE + + **/*.avsc + + + + + + + diff --git a/addons/common/marshallers/avro/src/main/java/org/kie/kogito/event/avro/AvroIO.java b/addons/common/marshallers/avro/src/main/java/org/kie/kogito/event/avro/AvroIO.java index 9fd104c3469..b7fc36d24bf 100644 --- a/addons/common/marshallers/avro/src/main/java/org/kie/kogito/event/avro/AvroIO.java +++ b/addons/common/marshallers/avro/src/main/java/org/kie/kogito/event/avro/AvroIO.java @@ -167,6 +167,7 @@ private static Schema loadSchema(String schemaName) throws IOException { private static final AvroMapper getAvroMapper() { AvroMapper mapper = new AvroMapper(); + mapper.configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true); mapper.findAndRegisterModules().registerModule(new SimpleModule().addSerializer(Utf8.class, new JsonSerializer() { @Override public void serialize(Utf8 value, JsonGenerator gen, SerializerProvider serializers) throws IOException { diff --git a/addons/common/marshallers/avro/src/test/avro/pojo.avsc b/addons/common/marshallers/avro/src/test/avro/pojo.avsc new file mode 100644 index 00000000000..faa12cee73d --- /dev/null +++ b/addons/common/marshallers/avro/src/test/avro/pojo.avsc @@ -0,0 +1,18 @@ +{ + "namespace": "org.kie.kogito.event.avro", + "type": "record", + "name": "Person", + "fields": [ + { + "name": "name", + "type": [ + "null", + "string" + ] + }, + { + "name": "age", + "type": "int" + } + ] +} \ No newline at end of file diff --git a/addons/common/marshallers/avro/src/test/java/org/kie/kogito/event/avro/AvroMarshallUnmarshallTest.java b/addons/common/marshallers/avro/src/test/java/org/kie/kogito/event/avro/AvroMarshallUnmarshallTest.java index a7ef1136c0c..adc45fbfaf5 100644 --- a/addons/common/marshallers/avro/src/test/java/org/kie/kogito/event/avro/AvroMarshallUnmarshallTest.java +++ b/addons/common/marshallers/avro/src/test/java/org/kie/kogito/event/avro/AvroMarshallUnmarshallTest.java @@ -61,4 +61,9 @@ void testJsonNodeMarshaller() throws IOException { void testJsonNodeCloudEventMarshaller() throws IOException { testCloudEventMarshalling(getJsonNodeCloudEvent(), JsonNode.class, new AvroCloudEventMarshaller(avroUtils), new AvroCloudEventUnmarshallerFactory(avroUtils)); } + + @Test + void testGeneratedPojoMarshaller() throws IOException { + testEventMarshalling(Person.newBuilder().setAge(0).setName("Pepe").build(), new AvroEventMarshaller(avroUtils), new AvroEventUnmarshaller(avroUtils)); + } } diff --git a/kogito-build/kogito-dependencies-bom/pom.xml b/kogito-build/kogito-dependencies-bom/pom.xml index 5d4953c8a65..686d59f3ebf 100644 --- a/kogito-build/kogito-dependencies-bom/pom.xml +++ b/kogito-build/kogito-dependencies-bom/pom.xml @@ -98,7 +98,8 @@ 1.7.13 2.0.4 13.4-alpine3.14 - + + 1.11.3 3.22.0 2.9.0 1.3 @@ -297,6 +298,11 @@ jackson-dataformat-avro ${version.com.fasterxml.jackson} + + org.apache.avro + avro + ${version.org.apache.avro} + com.jayway.jsonpath json-path