Skip to content

Commit

Permalink
Fix field naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaber committed Dec 30, 2023
1 parent b6c0a4b commit 3837820
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 3837820

Please sign in to comment.