jaxb

JAXB rename attribute

做~自己de王妃 提交于 2020-01-14 10:30:06
问题 I have some class with a terrible long name, which is transformed into XML with JAXB. Using @XmlRootElement(name="nicername") , I am able to rename the outer XML tag to <nicername> . How do I rename individual attributes with ugly names of the class to some nice name too ? 回答1: You can use the @XmlAttribute and @XmlElement annotations to change the XML names. If you annotate the fields be sure to use the @XmlAccessorType(XmlAccessType.FIELD) annotation on the class: @XmlRootElement(name="nice

Convert xs:string to java.util.UUID in jaxb

故事扮演 提交于 2020-01-14 08:15:50
问题 In jaxb, how do you convert a string in xsd to java.util.UUID? Is there a built-in data type converter or do I have to create my own custom converter? 回答1: This is much easier to do if you start with Java classes and use JAXB annotations. However, to do this using schema you must use a custom bindings file. Here is an example: Schema: (example.xsd) <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com" xmlns="http://www.example

JAXB unmarshalling with @XmlMixed Annotation

╄→尐↘猪︶ㄣ 提交于 2020-01-14 06:07:34
问题 I have a problem while unmarshalling an XML document. I found good hints here ("JAXB- @XmlMixed usage for reading @XmlValue and @XmlElement") but I wasn't able to adopt this on my code. First.. here is an example of the xml: <test> <content type="text">This is a content text</content> <content type="attributes"> <attributeGroup name="group1"> <attribute name="attr1">value1</attribute> </attributeGroup> <attributeGroup name="group2"> <attribute name="attr2">value2</attribute> <attribute name=

Make use of @XmlValue in subclass

别来无恙 提交于 2020-01-14 04:37:10
问题 I had this code working fine with EclipseLink 2.5.2, but moving to 2.6.0 breaks the XmlValue annotation: The property or field value cannot be annotated with XmlValue since it is a subclass of another XML-bound class. Base class look like this: public abstract class Baseclass { @XmlAttribute private String baseValue; // ... } One of two subclasses (composite pattern, class B can have a list of BaseClass elements): @XmlRootElement(name = "A") public class A extends BaseClass { @XmlValue

CXF code first webservice is creating wsdl with xs:element form=“unqualified” not picking up namespace

安稳与你 提交于 2020-01-14 04:06:12
问题 I'm creating webservices with CXF using the code first approach. I want to use namespaces, and therefore elementFormDefault is set to true . The WSDL is fine, except for the elements embedded in the complextypes, i get following xs:element having a form="unqualified" tag. But I want to get rid of the form=unqualified tag <xs:element form="unqualified" name="LikeSearch" type="xs:boolean"/> My package-info.java looks like this: @javax.xml.bind.annotation.XmlSchema(namespace="http://registry

Convert nil=“true” to null during unmarshal operation

ⅰ亾dé卋堺 提交于 2020-01-13 19:08:08
问题 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

Convert nil=“true” to null during unmarshal operation

你。 提交于 2020-01-13 19:06:32
问题 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

Where are the JAXB schemas published?

我的未来我决定 提交于 2020-01-13 14:01:39
问题 The JAXB 1.0 and JAXB 2.0 schemas are supposed to be available from the Bindings Schema for JAXB site. Unfortunately, it was last updated in 2005 and all of the links are broken. What is the official location of the schemas? There should be some authoritative source for v1.0, 2.0, 2.1 and 2.2. 回答1: JAXB XML Schemas JAXB 1.0 XML Schema JAXB 2.0 XML Schema It seems that there is no version 2.2 of the schema. The most recent would be 2.1. And an old post from the java.net forums (now defunct)

How do I add a namespace attribute to an element in JAXB when marshalling?

北城余情 提交于 2020-01-13 12:08:47
问题 I'm working with eBay's LMS (Large Merchant Services) and kept running into the error: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize. After a lot of trial and error I traced the problem down. It turns out this works: <?xml version="1.0" encoding="UTF-8"?> <BulkDataExchangeRequests xmlns="urn:ebay:apis:eBLBaseComponents"> <Header> <Version>583</Version> <SiteID>0</SiteID> </Header>

Unmarshaller and schema in JAXB

烈酒焚心 提交于 2020-01-13 11:08:09
问题 I have application that can save file in various formats (all of them is xml). So I should solve problem with determination in what format file have been saved. So, I see 2 solutions different formats have different schemas, so I could determine it by them. I set schemas in way that I get from here marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "bla-bla.xsd"); so I suppose I can get it using unmarshaller.getProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION) but it