Skip to content

Commit af199a6

Browse files
committed
fix JsonProperty without overridden name
1 parent a7c54fc commit af199a6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/main/java/jvm2dts/Converter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ private void processProperty(String propertyName, Method method, StringBuilder o
131131
for (Annotation annotation : annotations) {
132132
String annotationName = annotation.annotationType().getSimpleName();
133133
if (annotationName.equals("JsonIgnore")) return;
134-
else if (annotationName.equals("JsonProperty"))
135-
propertyName = (String) annotation.getClass().getMethod("value").invoke(annotation);
134+
else if (annotationName.equals("JsonProperty")) {
135+
var overriddenName = (String) annotation.getClass().getMethod("value").invoke(annotation);
136+
if (!overriddenName.isEmpty()) propertyName = overriddenName;
137+
}
136138
}
137139

138140
fieldBuffer.append(propertyName);

src/test/java/jvm2dts/ClassConverterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void record() {
7474
assertThat(converter.convert(Record.class)).isEqualTo("interface Record {" +
7575
"isCool: boolean; " +
7676
"hello: string; " +
77-
"notIncluded: number; " +
77+
"notIncluded: boolean; " +
7878
"world: string;}");
7979
}
8080

@@ -155,5 +155,5 @@ interface AnyId {
155155
}
156156

157157
record Record(String hello, String world, boolean isCool) {
158-
public int notIncluded() { return 0; }
158+
@JsonProperty public boolean notIncluded() { return false; }
159159
}

0 commit comments

Comments
 (0)