Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams @Setter @JsonInclude(JsonInclude.Include.NON_NULL) @JacksonXmlRootElement(localName = "user") public final class test { @JacksonXmlProperty(isAttribute = true) private String attr = "help"; @JacksonXmlText private String value; public test(String value) { this.value = value; public String getValue() { return value; public void setValue(String value) { this.value = value; public static void main(String[] args) throws JsonProcessingException { ObjectMapper xmlMapper = XmlMapper.builder().addModule(new ParameterNamesModule()).build(); System.out.println(xmlMapper.writeValueAsString(new test("help"))); Actual Output: <user><attr>help</attr>help</user> Expected Output: <user attr="help">help</user> Libraries Used: <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> <version>2.12.3</version> </dependency>

In spite of setting "@JacksonXmlProperty(isAttribute = true)", I am unable to figure out why the attribute is getting set as an element.

Working fine for me here using Randy's suggestion. Adding the getter/setter and without Lombok works fine, it generates: <user attr="help">help</user> Jorge Campos May 23, 2021 at 1:57

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .