Skip to content

Commit 99a4e2e

Browse files
authored
Merge pull request #10333 from colorcodecanvas/9845
Wrong generation of @JacksonXmlElementWrapper annotation
2 parents 4677fea + 5ebcf75 commit 99a4e2e

File tree

5 files changed

+115
-4
lines changed

5 files changed

+115
-4
lines changed

modules/swagger-codegen/src/main/resources/Java/pojo.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
3333
{{#isContainer}}
3434
{{#isXmlWrapped}}
3535
// items.xmlName={{items.xmlName}}
36-
@JacksonXmlElementWrapper(useWrapping = {{isXmlWrapped}}, {{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}localName = "{{#items.xmlName}}{{items.xmlName}}{{/items.xmlName}}{{^items.xmlName}}{{items.baseName}}{{/items.xmlName}}")
36+
@JacksonXmlElementWrapper(useWrapping = {{isXmlWrapped}}, {{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}localName = "{{#xmlName}}{{xmlName}}{{/xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
37+
@JacksonXmlProperty({{#isXmlAttribute}}isAttribute = true, {{/isXmlAttribute}}{{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}localName = "{{#items.xmlName}}{{items.xmlName}}{{/items.xmlName}}{{^items.xmlName}}{{baseName}}{{/items.xmlName}}")
3738
{{/isXmlWrapped}}
3839
{{/isContainer}}
3940
{{/withXml}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.10-SNAPSHOT
1+
2.4.16-SNAPSHOT
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# List
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**_123List** | **String** | | [optional]
8+
9+
10+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Swagger Petstore
3+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator program.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*/
12+
13+
14+
package io.swagger.client.model;
15+
16+
import java.util.Objects;
17+
import java.util.Arrays;
18+
import com.fasterxml.jackson.annotation.JsonProperty;
19+
import com.fasterxml.jackson.annotation.JsonCreator;
20+
import com.fasterxml.jackson.annotation.JsonValue;
21+
import io.swagger.annotations.ApiModel;
22+
import io.swagger.annotations.ApiModelProperty;
23+
import com.fasterxml.jackson.dataformat.xml.annotation.*;
24+
import javax.xml.bind.annotation.*;
25+
26+
/**
27+
* List
28+
*/
29+
30+
@XmlRootElement(name = "List")
31+
@XmlAccessorType(XmlAccessType.FIELD)
32+
@JacksonXmlRootElement(localName = "List")
33+
public class List {
34+
@JsonProperty("123-list")
35+
@JacksonXmlProperty(localName = "123-list")
36+
@XmlElement(name = "123-list")
37+
private String _123List = null;
38+
39+
public List _123List(String _123List) {
40+
this._123List = _123List;
41+
return this;
42+
}
43+
44+
/**
45+
* Get _123List
46+
* @return _123List
47+
**/
48+
@ApiModelProperty(value = "")
49+
public String get123List() {
50+
return _123List;
51+
}
52+
53+
public void set123List(String _123List) {
54+
this._123List = _123List;
55+
}
56+
57+
58+
@Override
59+
public boolean equals(java.lang.Object o) {
60+
if (this == o) {
61+
return true;
62+
}
63+
if (o == null || getClass() != o.getClass()) {
64+
return false;
65+
}
66+
List list = (List) o;
67+
return Objects.equals(this._123List, list._123List);
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
return Objects.hash(_123List);
73+
}
74+
75+
76+
@Override
77+
public String toString() {
78+
StringBuilder sb = new StringBuilder();
79+
sb.append("class List {\n");
80+
81+
sb.append(" _123List: ").append(toIndentedString(_123List)).append("\n");
82+
sb.append("}");
83+
return sb.toString();
84+
}
85+
86+
/**
87+
* Convert the given object to string with each line indented by 4 spaces
88+
* (except the first line).
89+
*/
90+
private String toIndentedString(java.lang.Object o) {
91+
if (o == null) {
92+
return "null";
93+
}
94+
return o.toString().replace("\n", "\n ");
95+
}
96+
97+
}
98+

samples/client/petstore/java/resttemplate-withXml/src/main/java/io/swagger/client/model/Pet.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public class Pet {
5252

5353
@JsonProperty("photoUrls")
5454
// items.xmlName=
55-
@JacksonXmlElementWrapper(useWrapping = true, localName = "photoUrls")
55+
@JacksonXmlElementWrapper(useWrapping = true, localName = "photoUrl")
56+
@JacksonXmlProperty(localName = "photoUrls")
5657
// Is a container wrapped=true
5758
// items.name=photoUrls items.baseName=photoUrls items.xmlName= items.xmlNamespace=
5859
// items.example= items.type=String
@@ -62,7 +63,8 @@ public class Pet {
6263

6364
@JsonProperty("tags")
6465
// items.xmlName=
65-
@JacksonXmlElementWrapper(useWrapping = true, localName = "tags")
66+
@JacksonXmlElementWrapper(useWrapping = true, localName = "tag")
67+
@JacksonXmlProperty(localName = "tags")
6668
// Is a container wrapped=true
6769
// items.name=tags items.baseName=tags items.xmlName= items.xmlNamespace=
6870
// items.example= items.type=Tag

0 commit comments

Comments
 (0)