Skip to content

Commit 42880c3

Browse files
committed
put property names containing non-word characters into quotes
1 parent af199a6 commit 42880c3

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/main/java/jvm2dts/Converter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private void processProperty(String propertyName, Method method, StringBuilder o
134134
else if (annotationName.equals("JsonProperty")) {
135135
var overriddenName = (String) annotation.getClass().getMethod("value").invoke(annotation);
136136
if (!overriddenName.isEmpty()) propertyName = overriddenName;
137+
if (!propertyName.matches("^\\w+$")) propertyName = "\"" + propertyName + "\"";
137138
}
138139
}
139140

src/test/java/jvm2dts/ClassConverterTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void record() {
7474
assertThat(converter.convert(Record.class)).isEqualTo("interface Record {" +
7575
"isCool: boolean; " +
7676
"hello: string; " +
77+
"\"@key\": string; " +
7778
"notIncluded: boolean; " +
7879
"world: string;}");
7980
}
@@ -156,4 +157,5 @@ interface AnyId {
156157

157158
record Record(String hello, String world, boolean isCool) {
158159
@JsonProperty public boolean notIncluded() { return false; }
160+
@JsonProperty("@key") public String key() { return ""; }
159161
}

0 commit comments

Comments
 (0)