简体   繁体   中英

What is sense type element in @XmlElement annotation

What is sens type element in @XmlElement annotation?

sth like this:

XmlElement(name = "userId", type = Long.class)
private Long id;

It is not used during XML generation.

The type property on @XmlElement is used in the following scenarios:

  1. Most common case is for untyped lists when you have List instead of List<String> you would use type=String.class .
  2. When your property type is an interface you use it to specify the impl class.
  3. When @XmlElement is used with @XmlElements to model a choice the type property maps the element to a class.
  4. Normally an XmlAdapter can't be applied to a datatype. Using type to bump it up to the correspond object type fixes this problem.
  5. If you want to force an xsi:type attribute to be marshalled you can specify type=Object.class .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM