xmladapter

How can JAXB XmlAdapter be used to marshall lists?

落花浮王杯 提交于 2021-02-19 06:48:05
问题 Instances of this class are part of a large object graph and are not at the root of the object graph: public class Day { public Day(LocalDate date, List<LocalTime> times) { this.date = date; this.times = times; } public Day() { this(null, null); } public LocalDate getDate() { return date; } public List<LocalTime> getTimes() { return times; } private final LocalDate date; private final List<LocalTime> times; } The object graph is converted to JSON using Jersey and JAXB. I have XmlAdapter s

JAXB override @XmlElement type of list

限于喜欢 提交于 2020-01-02 14:04:58
问题 There's a simple class Bean1 with a sublist of type BeanChild1 . @XmlRootElement(name="bean") @XmlAccessorType(XmlAccessType.PROPERTY) public static class Bean1 { public Bean1() { super(); } private List<BeanChild1> childList = new ArrayList<>(); @XmlElement(name="child") public List<BeanChild1> getChildList() { return childList; } public void setChildList(List<BeanChild1> pChildList) { childList = pChildList; } } public static class BeanChild1 { ... } I am trying to override the class, to

java XmlAdapter, is it possible to find out which enums are using that adapter?

浪子不回头ぞ 提交于 2019-12-24 16:18:25
问题 I've few of Java Enums which needs to mapped. I implement a XmlAdapter for marshalling and unmarshalling purpose. I would like to make the enums generic that I can call similar method of the enums from XmlAdapter. I also introduced an interface where all the enums implementing them. @XmlJavaAdapter(MyAdapter.class) public enum A implements Hello { doSomething1(); doSomething2(); } @XmlJavaAdapter(MyAdapter.class) public enum B implements Hello { doSomething1(); doSomething2(); } MyAdapter

Confused as how to use JAXB XML Adapter for my requirement

丶灬走出姿态 提交于 2019-12-23 07:56:22
问题 I am Using JAXB for unmarshalling process , for which the request comes from the UI to our service class . The below is the format of XML request . <SampleRequest user="testUser" account="testAccount" Specifier= "value1a,value1b,value1c : name2a,value2b,value2c"/> My requirement is that , the Specifier attribute has got Multiple series of values (: colon separated) i need to map each series of values to my custom java class I tried this way @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD

jaxb, can I use @XmlJavaTypeAdapter with @XmlElements?

[亡魂溺海] 提交于 2019-12-21 20:25:39
问题 Given the following annotations @XmlElements({ @XmlElement(name = "first", type = First.class), @XmlElement(name = "second", type = Second.class), @XmlElement(name = "third", type = Third.class), @XmlElement(name = "fourth", type = Fourth.class), @XmlElement(name = "fifth", type = Fifth.class), @XmlElement(name = "sixth", type = Sixth.class), @XmlElement(name = "seventh", type = Seventh.class)}) private List<Dimension> dimensions = new ArrayList<>(); And because of some funny legacy logic, I

JAXB @XmlAdapter: Map -> List adapter? (marshall only)

邮差的信 提交于 2019-12-18 16:30:46
问题 I have a Map<String, String> . The first idea everyone has is to convert it to a List<Pair<String,String>> ( Pair being a custom class). I've tried a @XmlAdapter like this: public class MapPropertiesAdapter extends XmlAdapter<List<Property>, Map<String,String>> { ... } But Eclipse MOXy, the JAXB impl I use, ended up with a ClassCastException - "can't convert HashMap to Collection". Is this conversion supported by JAXB? Or did I overlook some documentation part which explains why it isn't? PS:

JAXB override @XmlElement type of list

自闭症网瘾萝莉.ら 提交于 2019-12-06 05:48:15
There's a simple class Bean1 with a sublist of type BeanChild1 . @XmlRootElement(name="bean") @XmlAccessorType(XmlAccessType.PROPERTY) public static class Bean1 { public Bean1() { super(); } private List<BeanChild1> childList = new ArrayList<>(); @XmlElement(name="child") public List<BeanChild1> getChildList() { return childList; } public void setChildList(List<BeanChild1> pChildList) { childList = pChildList; } } public static class BeanChild1 { ... } I am trying to override the class, to change the type of the list. The new child-class (i.e. BeanChild2 ) extends the previous one (i.e.

jaxb, can I use @XmlJavaTypeAdapter with @XmlElements?

♀尐吖头ヾ 提交于 2019-12-04 12:48:17
Given the following annotations @XmlElements({ @XmlElement(name = "first", type = First.class), @XmlElement(name = "second", type = Second.class), @XmlElement(name = "third", type = Third.class), @XmlElement(name = "fourth", type = Fourth.class), @XmlElement(name = "fifth", type = Fifth.class), @XmlElement(name = "sixth", type = Sixth.class), @XmlElement(name = "seventh", type = Seventh.class)}) private List<Dimension> dimensions = new ArrayList<>(); And because of some funny legacy logic, I need to provide an adapter for Third.class. @XmlJavaTypeAdapter(ThirdAdapter.class) public class Third

JAXB marshal an ArrayList created by XmlAdapter

南笙酒味 提交于 2019-11-30 22:00:20
I want to adapt the XML representation of a HashMap field using XmlAdapter . I use an ArrayList to do that. However, when marshalling the ArrayList is not marshalled at all. Why is that? The code @XmlRootElement public class Foo { private HashMap<String, String> hashMap; public Foo() { this.hashMap = new HashMap<String, String>(); } @XmlJavaTypeAdapter(HashMapAdapter.class) public HashMap<String, String> getHashmap() { return hashMap; } public void setHashmap(HashMap<String, String> hashMap) { this.hashMap = hashMap; } } public final class HashMapAdapter extends XmlAdapter<ArrayList

JAXB marshal an ArrayList created by XmlAdapter

给你一囗甜甜゛ 提交于 2019-11-30 17:56:48
问题 I want to adapt the XML representation of a HashMap field using XmlAdapter . I use an ArrayList to do that. However, when marshalling the ArrayList is not marshalled at all. Why is that? The code @XmlRootElement public class Foo { private HashMap<String, String> hashMap; public Foo() { this.hashMap = new HashMap<String, String>(); } @XmlJavaTypeAdapter(HashMapAdapter.class) public HashMap<String, String> getHashmap() { return hashMap; } public void setHashmap(HashMap<String, String> hashMap)