Skip to content

Commit

Permalink
Revert "Upgrading siri-avro-mapper"
Browse files Browse the repository at this point in the history
  • Loading branch information
lassetyr committed Aug 23, 2024
1 parent 0628e8e commit 0dc3c02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
<dependency>
<groupId>org.entur</groupId>
<artifactId>siri-avro-mapper</artifactId>
<version>3.0.0</version>
<version>2.5.10</version>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ private void serializeEt(Exchange exchange) throws IOException {
etWriter.write(body, jsonEncoder);
jsonEncoder.flush();

exchange.getMessage().setBody(stream.toByteArray());
exchange.getMessage().setBody(replaceAvroEnums(stream.toByteArray()));
}


/*
Temporary legacy-hack to rewrite avro-data containing Enums to new schema-version where
enums are replaced with string for future compatibility.
*/
private static String replaceAvroEnums(byte[] byteArray) {
String json = new String(byteArray);
return json.replaceAll("\"org.entur.avro.realtime.siri.model.[a-zA-Z]*Enum\"", "\"string\"");
}

private void serializeVm(Exchange exchange) throws IOException {
Expand All @@ -50,8 +60,7 @@ private void serializeVm(Exchange exchange) throws IOException {
VehicleActivityRecord.SCHEMA$, stream);
vmWriter.write(body, jsonEncoder);
jsonEncoder.flush();

exchange.getMessage().setBody(stream.toByteArray());
exchange.getMessage().setBody(replaceAvroEnums(stream.toByteArray()));
}
private void serializeSx(Exchange exchange) throws IOException {
PtSituationElementRecord body = exchange.getMessage().getBody(PtSituationElementRecord.class);
Expand All @@ -60,7 +69,6 @@ private void serializeSx(Exchange exchange) throws IOException {
PtSituationElementRecord.SCHEMA$, stream);
sxWriter.write(body, jsonEncoder);
jsonEncoder.flush();

exchange.getMessage().setBody(stream.toByteArray());
exchange.getMessage().setBody(replaceAvroEnums(stream.toByteArray()));
}
}

0 comments on commit 0dc3c02

Please sign in to comment.