From c2ce77cd0a2464e01916318c59c17c140f82e8b1 Mon Sep 17 00:00:00 2001 From: Knative Prow Robot Date: Tue, 28 Nov 2023 15:56:06 +0000 Subject: [PATCH] ignore unknown fields in data plane contract (#3488) Signed-off-by: Calum Murray Co-authored-by: Calum Murray --- .../kafka/broker/core/eventbus/ContractPublisher.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/data-plane/core/src/main/java/dev/knative/eventing/kafka/broker/core/eventbus/ContractPublisher.java b/data-plane/core/src/main/java/dev/knative/eventing/kafka/broker/core/eventbus/ContractPublisher.java index 58fe0d8802..0c857fc68f 100644 --- a/data-plane/core/src/main/java/dev/knative/eventing/kafka/broker/core/eventbus/ContractPublisher.java +++ b/data-plane/core/src/main/java/dev/knative/eventing/kafka/broker/core/eventbus/ContractPublisher.java @@ -19,6 +19,7 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.util.JsonFormat; +import com.google.protobuf.util.JsonFormat.Parser; import dev.knative.eventing.kafka.broker.contract.DataPlaneContract; import io.vertx.core.eventbus.DeliveryOptions; import io.vertx.core.eventbus.EventBus; @@ -44,6 +45,8 @@ public class ContractPublisher implements Consumer, private final EventBus eventBus; private final String address; + private final Parser parser = JsonFormat.parser().ignoringUnknownFields(); + private long lastContract; public ContractPublisher(EventBus eventBus, String address) { @@ -68,7 +71,7 @@ public void updateContract(File newContract) { } try (final var fileReader = new FileReader(newContract); final var bufferedReader = new BufferedReader(fileReader)) { - final var contract = parseFromJson(bufferedReader); + final var contract = this.parseFromJson(bufferedReader); if (contract == null) { return; } @@ -89,10 +92,10 @@ public void updateContract(File newContract) { } } - public static DataPlaneContract.Contract parseFromJson(final Reader content) throws IOException { + public DataPlaneContract.Contract parseFromJson(final Reader content) throws IOException { try { final var contract = DataPlaneContract.Contract.newBuilder(); - JsonFormat.parser().merge(content, contract); + this.parser.merge(content, contract); return contract.build(); } catch (final InvalidProtocolBufferException ex) { logger.debug("failed to parse from JSON", ex);