@XmlRootElement 与 @JacksonXmlRootElement
@XmlRootElement vs @JacksonXmlRootElement
@XmlRootElement
@JacksonXmlRootElement
之间的确切区别是什么?
我知道@XmlRootElement 是通用的,但是当我检查包结构时两者是不同的。
所以用这个肯定有优缺点。
JacksonXmlRootElement 允许定义根级别的名称
define name of root element used for the root-level object when serialized
的原因
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).
@XmlRootElement
@JacksonXmlRootElement
之间的确切区别是什么?
我知道@XmlRootElement 是通用的,但是当我检查包结构时两者是不同的。
所以用这个肯定有优缺点。
JacksonXmlRootElement 允许定义根级别的名称
的原因define name of root element used for the root-level object when serialized
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).