Skip to content

Commit

Permalink
ignore unknown fields in data plane contract (knative-extensions#3486) (
Browse files Browse the repository at this point in the history
#904)

Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 authored Dec 8, 2023
1 parent d68e9bf commit eb01d97
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +45,8 @@ public class ContractPublisher implements Consumer<DataPlaneContract.Contract>,
private final EventBus eventBus;
private final String address;

private final Parser parser = JsonFormat.parser().ignoringUnknownFields();

private long lastContract;

public ContractPublisher(EventBus eventBus, String address) {
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit eb01d97

Please sign in to comment.