From 7e6395974453e71ccc4f87da6e3b9f436dcd3a16 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 2 Mar 2023 14:32:45 +0100 Subject: [PATCH] Add option to change to camelcase --- .../com/blueapron/connect/protobuf/ProtobufData.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/blueapron/connect/protobuf/ProtobufData.java b/src/main/java/com/blueapron/connect/protobuf/ProtobufData.java index 016b61a..5c7a46e 100644 --- a/src/main/java/com/blueapron/connect/protobuf/ProtobufData.java +++ b/src/main/java/com/blueapron/connect/protobuf/ProtobufData.java @@ -50,6 +50,7 @@ class ProtobufData { private final Schema schema; private final String legacyName; private final boolean useConnectSchemaMap; + private final boolean useCamelCase; public static final Descriptors.FieldDescriptor.Type[] PROTO_TYPES_WITH_DEFAULTS = new Descriptors.FieldDescriptor.Type[] { INT32, INT64, SINT32, SINT64, FLOAT, DOUBLE, BOOL, STRING, BYTES, ENUM }; private HashMap connectProtoNameMap = new HashMap(); @@ -74,7 +75,7 @@ private String getProtoMapKey(String descriptorContainingTypeName, String connec } private String getConnectFieldName(Descriptors.FieldDescriptor descriptor) { - String name = descriptor.getName(); + String name = useCamelCase ? descriptor.getJsonName() : descriptor.getName(); for (Map.Entry option: descriptor.getOptions().getAllFields().entrySet()) { if (option.getKey().getFullName().equalsIgnoreCase(this.legacyName)) { name = option.getValue().toString(); @@ -93,9 +94,14 @@ private String getProtoFieldName(String descriptorForTypeName, String connectFie this(clazz, legacyName, false); } - ProtobufData(Class clazz, String legacyName, boolean useConnectSchemaMap ) { + ProtobufData(Class clazz, String legacyName, boolean useConnectSchemaMap) { + this(clazz, legacyName, useConnectSchemaMap, false); + } + + ProtobufData(Class clazz, String legacyName, boolean useConnectSchemaMap, boolean useCamelCase) { this.legacyName = legacyName; this.useConnectSchemaMap = useConnectSchemaMap; + this.useCamelCase = useCamelCase; try { this.newBuilder = clazz.getDeclaredMethod("newBuilder");