Skip to content

Commit

Permalink
[Fix #3436] Ignoring unknown properties (#3437)
Browse files Browse the repository at this point in the history
* [Fix #3436] Ignoring unknown properties

* [Fix #3436] Adding unit test
  • Loading branch information
fjtirado authored Mar 13, 2024
1 parent 3c00b57 commit 5ac6c8a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
26 changes: 25 additions & 1 deletion addons/common/marshallers/avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,29 @@
</dependency>

</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${version.org.apache.avro}</version>
<executions>
<execution>
<phase>generate-test-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/test/avro/</sourceDirectory>
<fieldVisibility>PRIVATE</fieldVisibility>
<includes>
<include>**/*.avsc</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<Utf8>() {
@Override
public void serialize(Utf8 value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
Expand Down
18 changes: 18 additions & 0 deletions addons/common/marshallers/avro/src/test/avro/pojo.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"namespace": "org.kie.kogito.event.avro",
"type": "record",
"name": "Person",
"fields": [
{
"name": "name",
"type": [
"null",
"string"
]
},
{
"name": "age",
"type": "int"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
8 changes: 7 additions & 1 deletion kogito-build/kogito-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
<version.org.mozilla.rhino>1.7.13</version.org.mozilla.rhino>
<version.org.redis>2.0.4</version.org.redis>
<version.org.postgres>13.4-alpine3.14</version.org.postgres>

<!-- we align to version used by quarkus -->
<version.org.apache.avro>1.11.3</version.org.apache.avro>
<version.org.assertj>3.22.0</version.org.assertj>
<version.org.json-unit-assertj>2.9.0</version.org.json-unit-assertj>
<version.org.hamcrest>1.3</version.org.hamcrest> <!-- else old version coming from Mockito wins and breaks tests -->
Expand Down Expand Up @@ -297,6 +298,11 @@
<artifactId>jackson-dataformat-avro</artifactId>
<version>${version.com.fasterxml.jackson}</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>${version.org.apache.avro}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
Expand Down

0 comments on commit 5ac6c8a

Please sign in to comment.