jaxb2

Duplicated field in generated XML using JAXB

谁说我不能喝 提交于 2019-12-06 23:29:23
问题 This is my scenario. I have a generic class: public class Tuple<T> extends ArrayList<T> { //... public Tuple(T ...members) { this(Arrays.asList(members)); } @XmlElementWrapper(name = "tuple") @XmlElement(name = "value") public List<T> getList() { return this; } } And a child class: public class StringTuple extends Tuple<String> { public StringTuple(String ...members) { super(members); } //explanation of why overriding this method soon ... @XmlElementWrapper(name = "tuple") @XmlElement(name =

Validate nested object from complex object using jaxb

不羁的心 提交于 2019-12-06 12:13:18
问题 I have a xml representation of object like OrderList (has list of) Orders and each order has a list of commodities. I want to validate my commodities and if not valid I want to remove them from order. If all commodities are invalid then I remove the order from the orderlist. I have been able to validate Orderlist JAXBContext jaxbContext = JAXBContext.newInstance("com.jaxb"); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File

JAXB - marshal java object with XML string field

ぃ、小莉子 提交于 2019-12-06 11:44:35
suppose i have an object with String property that has an XML string. like: class myObject { String xml; @XmlElement(name = "xml", type = String.class) public String getXml() { return xml; } public void setXml(String xml) { this.xml = xml; } } i set an XML String to this property - such as myObject.setXml("<xml>bbb</xml>"); now i want to marshal it using JAXB and i get: <xml><xml>bbb</xml></xml> where i want to get <xml>bbb</xml> how can i do it? EDIT: the problem is that String xml, stores a well formatted XML as a string. so I want this string to be marshaled without escaping the XML

Is it valid to specify xsi:type for an local complexType?

别说谁变了你拦得住时间么 提交于 2019-12-06 11:30:52
We are having a problem with xsi:type since upgrading our server to jaxb 2. The xml client request in question was parsed ok when the server was running jaxb 1, but since upgrading to jaxb 2 we are seeing an error along the lines of: Error::cvc-elt.4.2: Cannot resolve 'er-request' to a type definition for element 'er-request' A client is specifying xsi:type as an attribute in a xml tag, but I don't think it's valid since the complex type in question has no such name. <?xml version="1.0" encoding="UTF-8"?> <er-request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="100007" xsi:type=

Jaxb 2.0 Schema validation problem

爱⌒轻易说出口 提交于 2019-12-06 06:39:43
问题 I am working with Jaxb 2.x and was trying to validate XML document with the given XSD using the following tutorial Tutorial Link hers is the code i have written unmarshaller.setSchema(schema); SAXSource source = new SAXSource(new InputSource(xmlFileLocation)); Validator validator = schema.newValidator(); validator.setErrorHandler(new XMLErrorHandler<Object>()); try { validator.validate(source); } catch (SAXException e) { and my XMLErrorHanlder class have following signature public class

packagename doesnt contain ObjectFactory.class or jaxb.index

跟風遠走 提交于 2019-12-06 05:02:10
While deploying my project to a tomcat-server, I get constantly this exception: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'marshaller': Invocation of init method failed; nested exception is org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: "be.icredit.einvoice.proxy.customerdaoservice" doesnt contain ObjectFactory.class or jaxb.index But it does have an ObjectFactory.class! Im using Spring, Maven and Jaxb2 My POM: <project xmlns="http://maven.apache.org/POM/4.0

Can I customize JAXB @XmlElementWrapper elements for a java.util.Map

喜夏-厌秋 提交于 2019-12-06 04:43:02
问题 I'm trying to learn to use Map with Jaxb. I did this: @XmlElementWrapper(name = "phoneNumbers", nillable = true) private Map<String, PhoneNumber> phoneNumbers; and the result was: <xs:element nillable="true" name="phoneNumbers"> <xs:complexType> <xs:sequence> <xs:element name="entry" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="key" minOccurs="0" type="xs:string"/> <xs:element name="value" minOccurs="0" type="PhoneNumberType"/> </xs:sequence> </xs

convert object into JAXBElement

家住魔仙堡 提交于 2019-12-06 00:32:15
问题 I want to implement a method which returns JAXBElement following is the code @XmlRootElement(name = "history") @XmlAccessorType(XmlAccessType.FIELD) public class IBHistoryInfo { @XmlElement(name="trade") private List<IBTradeInfo> mTrade; public void updateTradeValue(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps){ IBTradeInfo info = new IBTradeInfo(); info.setReqId(reqId); info.setDate(date); info.setOpen(open);

Jaxb namespaces for java.util.Map properties

。_饼干妹妹 提交于 2019-12-05 20:03:55
I have a simple class that contains a hashmap: @XmlRootElement() public class Customer { private long id; private String name; private Map<String, String> attributes; public Map<String, String> getAttributes() { return attributes; } public void setAttributes(Map<String, String> attributes) { this.attributes = attributes; } @XmlAttribute public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public static void main(String[] args) throws Exception { JAXBContext jc =

Convert nil=“true” to null during unmarshal operation

限于喜欢 提交于 2019-12-05 19:36:06
I am receiving XML from a server whose schema specifies nearly every element as: <xs:element name="myStringElementName" type="xs:string" nillable="true" minOccurs="0"/> <xs:element name="myIntElementName" type="xs:int" nillable="true" minOccurs="0"/> I'm trying to find a clean way to convert every element that I receive that is marked as xsi:nil="true" to a null when it is unmarshalled into a JAXB object. So something like this: <myIntElementName xsi:nil="true" /> Should result in my JAXB object having a myIntElementName property with a value of null, rather than a JAXBElement object with a