Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong generation of @JacksonXmlElementWrapper annotation #10333

Merged
merged 7 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
{{#isContainer}}
{{#isXmlWrapped}}
// items.xmlName={{items.xmlName}}
@JacksonXmlElementWrapper(useWrapping = {{isXmlWrapped}}, {{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}localName = "{{#items.xmlName}}{{items.xmlName}}{{/items.xmlName}}{{^items.xmlName}}{{items.baseName}}{{/items.xmlName}}")
@JacksonXmlElementWrapper(useWrapping = {{isXmlWrapped}}, {{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}localName = "{{#xmlName}}{{xmlName}}{{/xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
Copy link
Contributor Author

@sanjeevgiri sanjeevgiri Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JacksonXmlElementWrapper should use the swaggerArrayProperty.xml.name as its local name instead of swaggerArrayProperty.items.xml.name

In order to customize the name for the wrapped xml element, JacksonXmlProperty annotation also must be included.

@JacksonXmlProperty({{#isXmlAttribute}}isAttribute = true, {{/isXmlAttribute}}{{#xmlNamespace}}namespace="{{xmlNamespace}}", {{/xmlNamespace}}localName = "{{#items.xmlName}}{{items.xmlName}}{{/items.xmlName}}{{^items.xmlName}}{{baseName}}{{/items.xmlName}}")
{{/isXmlWrapped}}
{{/isContainer}}
{{/withXml}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.10-SNAPSHOT
2.4.16-SNAPSHOT
10 changes: 10 additions & 0 deletions samples/client/petstore/java/resttemplate-withXml/docs/List.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# List

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**_123List** | **String** | | [optional]



Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Swagger Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/


package io.swagger.client.model;

import java.util.Objects;
import java.util.Arrays;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.*;
import javax.xml.bind.annotation.*;

/**
* List
*/

@XmlRootElement(name = "List")
@XmlAccessorType(XmlAccessType.FIELD)
@JacksonXmlRootElement(localName = "List")
public class List {
@JsonProperty("123-list")
@JacksonXmlProperty(localName = "123-list")
@XmlElement(name = "123-list")
private String _123List = null;

public List _123List(String _123List) {
this._123List = _123List;
return this;
}

/**
* Get _123List
* @return _123List
**/
@ApiModelProperty(value = "")
public String get123List() {
return _123List;
}

public void set123List(String _123List) {
this._123List = _123List;
}


@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
List list = (List) o;
return Objects.equals(this._123List, list._123List);
}

@Override
public int hashCode() {
return Objects.hash(_123List);
}


@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class List {\n");

sb.append(" _123List: ").append(toIndentedString(_123List)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class Pet {

@JsonProperty("photoUrls")
// items.xmlName=
@JacksonXmlElementWrapper(useWrapping = true, localName = "photoUrls")
@JacksonXmlElementWrapper(useWrapping = true, localName = "photoUrl")
@JacksonXmlProperty(localName = "photoUrls")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...
  <photoUrls>
    <photoUrl>
      ...
    </photoUrl>
     <photoUrl>
        ...
     </photoUrl>
  <photoUrls>

// Is a container wrapped=true
// items.name=photoUrls items.baseName=photoUrls items.xmlName= items.xmlNamespace=
// items.example= items.type=String
Expand All @@ -62,7 +63,8 @@ public class Pet {

@JsonProperty("tags")
// items.xmlName=
@JacksonXmlElementWrapper(useWrapping = true, localName = "tags")
@JacksonXmlElementWrapper(useWrapping = true, localName = "tag")
@JacksonXmlProperty(localName = "tags")
// Is a container wrapped=true
// items.name=tags items.baseName=tags items.xmlName= items.xmlNamespace=
// items.example= items.type=Tag
Expand Down