@XmlRootElement 与 @JacksonXmlRootElement

@XmlRootElement vs @JacksonXmlRootElement

@XmlRootElement @JacksonXmlRootElement 之间的确切区别是什么?

我知道@XmlRootElement 是通用的,但是当我检查包结构时两者是不同的。

所以用这个肯定有优缺点。

JacksonXmlRootElement 允许定义根级别的名称

define name of root element used for the root-level object when serialized

这里是添加@JacksonXmlRootElement

的原因

JAXB allows you to override the name of the root element (using @XmlRootElement when generating XML. For example, rendering this class to XML:

@JsonIgnoreProperties( {"meal", "notMeal", "mealNameDisplay"} ) public class MealEvent...

Generates XML like this:

lunch ... But I'd like the root element to be 'meal' instead of 'MealEvent'.

FWIW, I tried the wild guess using @JsonTypeName( "meal" ) as well – it had no effect.

Implemented: now there is @JacksonXmlRootElement (named similar to JAXB annotation, just with "Jackson" prefix to reduce confusion).