Skip to content

Commit f6a213f

Browse files
authored
fix: move jsonproperty annotation to getter (#2359)
1 parent e5a8172 commit f6a213f

File tree

5 files changed

+139
-106
lines changed

5 files changed

+139
-106
lines changed

examples/java-generate-jackson-annotation/__snapshots__/index.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
exports[`Should be able to generate data models for jackson annotation and should log expected output to console 1`] = `
44
Array [
55
"public class Root {
6-
@JsonProperty(\\"min_number_prop\\")
76
@JsonInclude(JsonInclude.Include.NON_NULL)
87
private Double minNumberProp;
9-
@JsonProperty(\\"max_number_prop\\")
108
@JsonInclude(JsonInclude.Include.NON_NULL)
119
private Double maxNumberProp;
1210
@JsonAnySetter
1311
@JsonInclude(JsonInclude.Include.NON_NULL)
1412
private Map<String, Object> additionalProperties;
1513
14+
@JsonProperty(\\"min_number_prop\\")
1615
public Double getMinNumberProp() { return this.minNumberProp; }
1716
public void setMinNumberProp(Double minNumberProp) { this.minNumberProp = minNumberProp; }
1817
18+
@JsonProperty(\\"max_number_prop\\")
1919
public Double getMaxNumberProp() { return this.maxNumberProp; }
2020
public void setMaxNumberProp(Double maxNumberProp) { this.maxNumberProp = maxNumberProp; }
2121

src/generators/java/presets/JacksonPreset.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ export const JAVA_JACKSON_PRESET: JavaPreset = {
5151
return renderer.renderBlock(blocks);
5252
}
5353

54-
blocks.push(
55-
renderer.renderAnnotation(
56-
'JsonProperty',
57-
`"${property.unconstrainedPropertyName}"`
58-
)
59-
);
60-
6154
if (!property.required) {
6255
blocks.push(
6356
renderer.renderAnnotation(
@@ -85,6 +78,13 @@ export const JAVA_JACKSON_PRESET: JavaPreset = {
8578
const blocks: string[] = [];
8679
if (hasUnwrappedOptions) {
8780
blocks.push(renderer.renderAnnotation('JsonAnyGetter'));
81+
} else {
82+
blocks.push(
83+
renderer.renderAnnotation(
84+
'JsonProperty',
85+
`"${property.unconstrainedPropertyName}"`
86+
)
87+
);
8888
}
8989
blocks.push(content);
9090
return renderer.renderBlock(blocks);

0 commit comments

Comments
 (0)