Skip to content

Commit f4bf2d1

Browse files
committed
#27 - @JSON(naming = Naming.LowerUnderscore) not work
1 parent 6a18506 commit f4bf2d1

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

jsonb-generator/src/main/java/io/avaje/jsonb/generator/NamingConventionReader.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NamingConventionReader {
1919
if (JSON_ANNOTATION.equals(mirror.getAnnotationType().toString())) {
2020
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) {
2121
if (entry.getKey().toString().equals(NAMING_ATTRIBUTE)) {
22-
namingConvention = NamingConvention.of(Json.Naming.valueOf(entry.getValue().toString()));
22+
namingConvention = NamingConvention.of(naming(entry.getValue().toString()));
2323
} else if (entry.getKey().toString().equals(TYPEPROPERTY_ATTRIBUTE)) {
2424
typeProperty = Util.trimQuotes(entry.getValue().toString());
2525
}
@@ -28,6 +28,14 @@ class NamingConventionReader {
2828
}
2929
}
3030

31+
static Json.Naming naming(String entry) {
32+
int pos = entry.lastIndexOf('.');
33+
if (pos > -1) {
34+
entry = entry.substring(pos + 1);
35+
}
36+
return Json.Naming.valueOf(entry);
37+
}
38+
3139
NamingConvention get() {
3240
return namingConvention != null ? namingConvention : NamingConvention.of(Json.Naming.Match);
3341
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.avaje.jsonb.generator;
2+
3+
import io.avaje.jsonb.Json;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
class NamingConventionReaderTest {
9+
10+
@Test
11+
void naming_expected() {
12+
Json.Naming naming = NamingConventionReader.naming("LowerUnderscore");
13+
assertThat(naming).isEqualTo(Json.Naming.LowerUnderscore);
14+
}
15+
16+
@Test
17+
void naming_namingWithPrefix() {
18+
Json.Naming naming = NamingConventionReader.naming("Naming.LowerUnderscore");
19+
assertThat(naming).isEqualTo(Json.Naming.LowerUnderscore);
20+
21+
naming = NamingConventionReader.naming("io.avaje.jsonb.Json.Naming.LowerUnderscore");
22+
assertThat(naming).isEqualTo(Json.Naming.LowerUnderscore);
23+
24+
naming = NamingConventionReader.naming("io.avaje.jsonb.Json.Naming.io.avaje.jsonb.Json.Naming.LowerUnderscore");
25+
assertThat(naming).isEqualTo(Json.Naming.LowerUnderscore);
26+
}
27+
28+
}

0 commit comments

Comments
 (0)