Skip to content

Commit

Permalink
fix XML annotations on model properties (JavaSpring)
Browse files Browse the repository at this point in the history
* generate JAXB annotations for attributes and elements

* generate wrapper annotations (JAXB and Jackson)

* use XML config from items for annotations of containers
  • Loading branch information
chschu committed Apr 15, 2024
1 parent 2abcb4f commit 0879303
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.hibernate.validator.constraints.*;
{{#withXml}}
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
{{/withXml}}
{{/jackson}}
{{#swagger2AnnotationLibrary}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,31 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
{{/swagger1AnnotationLibrary}}
{{#jackson}}
@JsonProperty("{{baseName}}")
{{#withXml}}
@JacksonXmlProperty({{#isXmlAttribute}}isAttribute = true, {{/isXmlAttribute}}{{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/withXml}}
{{#withXml}}
{{#isXmlAttribute}}
@XmlAttribute({{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
@JacksonXmlProperty(isAttribute = true, {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/isXmlAttribute}}
{{^isXmlAttribute}}
{{#isContainer}}
{{#items}}
@XmlElement({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
@JacksonXmlProperty({{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/items}}
{{#isXmlWrapped}}
@XmlElementWrapper({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
@JacksonXmlElementWrapper({{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/isXmlWrapped}}
{{^isXmlWrapped}}
@JacksonXmlElementWrapper(useWrapping = false)
{{/isXmlWrapped}}
{{/isContainer}}
{{^isContainer}}
@XmlElement({{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
@JacksonXmlProperty({{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
{{/isContainer}}
{{/isXmlAttribute}}
{{/withXml}}
{{/jackson}}
{{#deprecated}}
@Deprecated
Expand Down

0 comments on commit 0879303

Please sign in to comment.