jaxb

Line number of individual XML element while unmarshalling using jaxb

笑着哭i 提交于 2020-01-15 07:51:26
问题 I have a class Person with attributes name and address. I display it in a XML. While unmarshalling from XML will it be possible to get line number for name and address separately. I tried using Locator. But it does not provide individual line numbers. 回答1: The EclipseLink JAXB (MOXy) and the JAXB reference implementation each have their own @XmlLocation annotations for supporting this use case. This allows you to store the location on the XML element corresponding to the object as an instance

How to make a deep copy of JAXB object like xmlbean XmlObject.copy()?

不打扰是莪最后的温柔 提交于 2020-01-15 06:49:47
问题 I have been tasked with refactoring some components that used xmlbeans to now make use of jaxb. Everything is going great, until I get to a place where the previous author has called the copy() function of one of the XmlObjects. Since all objects in xmlbeans extend XmlObject, we get the magic deep copy function for free. Jaxb does not seem to provide this for us. What is the correct and simple way to make a deep copy of a Jaxb object? 回答1: You could make your JAXB classes serializable and

How to make a deep copy of JAXB object like xmlbean XmlObject.copy()?

懵懂的女人 提交于 2020-01-15 06:49:40
问题 I have been tasked with refactoring some components that used xmlbeans to now make use of jaxb. Everything is going great, until I get to a place where the previous author has called the copy() function of one of the XmlObjects. Since all objects in xmlbeans extend XmlObject, we get the magic deep copy function for free. Jaxb does not seem to provide this for us. What is the correct and simple way to make a deep copy of a Jaxb object? 回答1: You could make your JAXB classes serializable and

Create a POJO using JSON data

拥有回忆 提交于 2020-01-15 06:49:31
问题 I am having a JSON coming from response payload of rest API. below is structure of simplified JSON but the actual is much more complex. { "hardware": { "cores": 2, "cpu": 1, }, "name": "machine11", "network": [ { "interface_name": "intf1", "interface_ip": "1.1.1.1", "interface_mac": "aa : aa: aa: aa: aa" } ] } Now I have to write POJO class to bind the JSON structure using JAXB annotations (javax.xml.bind.annotation.*). Can anyone help me how to write POJO class for a complex JSON structure

Import namespace - Cannot resolve the name to a(n) 'type definition' component

房东的猫 提交于 2020-01-15 01:19:46
问题 Context: I am generating java classes from xsd files using maven-jaxb plugin. All my .xsd files are in a single location - src/main/resource directory. Problem: Everything works fine when xsd's don't reference/import other xsd's with a different target namespace. However when the following xsd below (with targetNamespace="http://www.companyA.com/someservice") imports another xsd filename.xsd from a different namespace (namespace="http://www.companyB.com/"), I get the above error: Cannot

Import namespace - Cannot resolve the name to a(n) 'type definition' component

痴心易碎 提交于 2020-01-15 01:19:18
问题 Context: I am generating java classes from xsd files using maven-jaxb plugin. All my .xsd files are in a single location - src/main/resource directory. Problem: Everything works fine when xsd's don't reference/import other xsd's with a different target namespace. However when the following xsd below (with targetNamespace="http://www.companyA.com/someservice") imports another xsd filename.xsd from a different namespace (namespace="http://www.companyB.com/"), I get the above error: Cannot

Moxy not honoring the super class/interface properties

跟風遠走 提交于 2020-01-14 14:12:28
问题 enter code here I have the properties for a Customer spread across two interfaces as shown below. I have the external xml binding defined using the sub interface ICustomer. When I marshall the pojo to xml, it seems like the Moxy is ignoring the super interface's property firstName . Is this a bug or do I need to explicitly specify each of these two interfaces in the xml meta-data? Base interface public interface IBaseCustomer { String getFirstName(); void setFirstName(final String firstName);

Moxy not honoring the super class/interface properties

徘徊边缘 提交于 2020-01-14 14:09:22
问题 enter code here I have the properties for a Customer spread across two interfaces as shown below. I have the external xml binding defined using the sub interface ICustomer. When I marshall the pojo to xml, it seems like the Moxy is ignoring the super interface's property firstName . Is this a bug or do I need to explicitly specify each of these two interfaces in the xml meta-data? Base interface public interface IBaseCustomer { String getFirstName(); void setFirstName(final String firstName);

JAXB How to marshal an element both optional or nillable

Deadly 提交于 2020-01-14 12:50:07
问题 I'm trying to marshal an element which can be null and in some cases should be not written in the final XML at all, in some other cases I should specify that it is nillable. Consider the following example <root> <element> <sub1>Whatever1</sub1> <sub2 xsi:nil="true"/> </element> <element> <sub1>Whatever2</sub1> <sub2>Not empty</sub2> </element> <element> <sub1>Whatever3</sub1> </element> </root> The element "sub2" is the one I'm having trouble with. From my understanding I can easily achieve

JAXB rename attribute

可紊 提交于 2020-01-14 10:33:23
问题 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