Skip to content

Commit

Permalink
Merge pull request #114 from HubSpot/jh/rm-naming-strategy-base
Browse files Browse the repository at this point in the history
Fix field naming
  • Loading branch information
jhaber authored Dec 30, 2023
2 parents ad50263 + 3837820 commit ac64b70
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
Expand All @@ -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
Expand Down

0 comments on commit ac64b70

Please sign in to comment.