From 3837820584f15c0c6c3b1794814ae223450d0077 Mon Sep 17 00:00:00 2001 From: jhaber Date: Sat, 30 Dec 2023 10:17:48 -0500 Subject: [PATCH] Fix field naming --- .../protobuf/PropertyNamingStrategyWrapper.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hubspot/jackson/datatype/protobuf/PropertyNamingStrategyWrapper.java b/src/main/java/com/hubspot/jackson/datatype/protobuf/PropertyNamingStrategyWrapper.java index ac0f4f7..73c1e70 100644 --- a/src/main/java/com/hubspot/jackson/datatype/protobuf/PropertyNamingStrategyWrapper.java +++ b/src/main/java/com/hubspot/jackson/datatype/protobuf/PropertyNamingStrategyWrapper.java @@ -14,8 +14,8 @@ @SuppressWarnings("serial") public class PropertyNamingStrategyWrapper { - private static final PropertyNamingStrategy SNAKE_TO_CAMEL = new SnakeToCamelNamingStrategy(); - private static final PropertyNamingStrategy NO_OP = new NoOpNamingStrategy(); + private static final NamingBase SNAKE_TO_CAMEL = new SnakeToCamelNamingStrategy(); + private static final NamingBase NO_OP = new NoOpNamingStrategy(); private final Class messageType; private final MapperConfig mapperConfig; @@ -43,7 +43,7 @@ public PropertyNamingStrategyWrapper( public String translate(String fieldName) { AnnotatedField annotatedField = null; try { - Field field = messageType.getDeclaredField(fieldName + "_"); + Field field = messageType.getDeclaredField(javaFieldName(fieldName)); annotatedField = new AnnotatedField( new TypeResolutionContext.Empty(mapperConfig.getTypeFactory()), @@ -57,6 +57,12 @@ public String translate(String fieldName) { return delegate.nameForField(mapperConfig, annotatedField, fieldName); } + private static String javaFieldName(String fieldName) { + return ( + (fieldName.contains("_") ? SNAKE_TO_CAMEL.translate(fieldName) : fieldName) + "_" + ); + } + private static class SnakeToCamelNamingStrategy extends NamingBase { @Override