Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Add option to change to camelcase
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Mar 2, 2023
1 parent 44641a1 commit 7e63959
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/blueapron/connect/protobuf/ProtobufData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> connectProtoNameMap = new HashMap<String, String>();

Expand All @@ -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<Descriptors.FieldDescriptor, Object> option: descriptor.getOptions().getAllFields().entrySet()) {
if (option.getKey().getFullName().equalsIgnoreCase(this.legacyName)) {
name = option.getValue().toString();
Expand All @@ -93,9 +94,14 @@ private String getProtoFieldName(String descriptorForTypeName, String connectFie
this(clazz, legacyName, false);
}

ProtobufData(Class<? extends com.google.protobuf.GeneratedMessageV3> clazz, String legacyName, boolean useConnectSchemaMap ) {
ProtobufData(Class<? extends com.google.protobuf.GeneratedMessageV3> clazz, String legacyName, boolean useConnectSchemaMap) {
this(clazz, legacyName, useConnectSchemaMap, false);
}

ProtobufData(Class<? extends com.google.protobuf.GeneratedMessageV3> clazz, String legacyName, boolean useConnectSchemaMap, boolean useCamelCase) {
this.legacyName = legacyName;
this.useConnectSchemaMap = useConnectSchemaMap;
this.useCamelCase = useCamelCase;

try {
this.newBuilder = clazz.getDeclaredMethod("newBuilder");
Expand Down

0 comments on commit 7e63959

Please sign in to comment.