JAXB: How to suppress surrounding XmlElement when using XmlJavaTypeAdapter?

六月ゝ 毕业季﹏ 提交于 2019-12-02 04:31:01
bdoughan

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

You could use the @XmlPath(".") extension in MOXy to map this use case. Specifying "." as the path indicates that the contents of the child should be written into the parent objects element.

import java.util.HashMap;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Foo {

    @XmlJavaTypeAdapter(MyMapItemAdapter.class)
    @XmlPath(".")
    Map<String, MapItem> map = new TreeMap<String, MapItem>();       

}

Full Example

For More Information

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!