Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use lombok with @XmlElement

Tags:

How can I use Lombok in conjunction with my @XmlElement tags so that I can unmarshall the object?

I have about 20 properties, so I'm looking to not write an explicit getter and setter for each with the XmlElement tags on the setters.

like image 210
MiketheCalamity Avatar asked Aug 07 '15 18:08

MiketheCalamity


People also ask

Can we use Lombok in Spring MVC?

Maven dependencies for Spring Boot and LombokFollowing dependencies are used to work with Spring Boot and Lombok and for testing Spring components. Make sure you already installed lombok setup for your IDE. To Setup in Eclipse or in Spring Tool Suite refer to our Lombok Maven example setup with Eclipse.

Does spring boot use Lombok?

Lombok Dependency Note: If you're using a Spring Boot POM, Project Lombok is a curated dependency. Thus, you can omit the version (which will then be inherited from the Spring Boot parent POM).

Does Lombok affect performance?

It does not decrease performance at runtime, there is a performance flaw at compiletime.

What is the use of @data in Lombok?

@Data is a convenient shortcut annotation that bundles the features of @ToString , @EqualsAndHashCode , @Getter / @Setter and @RequiredArgsConstructor together: In other words, @Data generates all the boilerplate that is normally associated with simple POJOs (Plain Old Java Objects) and beans: getters for all fields, ...


1 Answers

This gets the job done:

@Data
@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)      // UPDATE: Need this or else exception
public class Data {
    @XmlElement(name = "test")
    public double testData;
}
like image 116
MiketheCalamity Avatar answered Nov 05 '22 07:11

MiketheCalamity