jaxb

How to configure JAXB so it trims whitespaces by default

不问归期 提交于 2020-02-13 07:16:29
问题 I would like to configure JAXB so that it trims whitespaces on all string fields I saw the following answer : How to configure JAXB so it trims whitespaces when unmarshalling tag value? But I do not want to have to annotate all string fields as per the suggested answer @XmlElement(required=true) @XmlJavaTypeAdapter(MyNormalizedStringAdapter.class) String name; Thanks! 回答1: Create a XmlAdapter. package com.foo.bar; public class StringTrimAdapter extends XmlAdapter<String, String> { @Override

JAXB and Composite Pattern

二次信任 提交于 2020-02-06 04:15:46
问题 I'm working with JAXB right now and I'm struggling to annotate my composite notion of precondition query so that JAXB would be happy. A precondition query can be: simple : only a text node containing the query compound OR : the preconditions of 1 precondition query OR the other matches AND : the preconditions of 1 precondition query AND the other matches Of course, compound queries can be made of compound queries, just like in the following example: <precondition> <or> <and> <query>foo</query

Dozer deep mapping not working

匆匆过客 提交于 2020-02-05 17:12:47
问题 I am trying to use dozer 4.1 to map between classes. I have a source class that looks like this: public class initRequest{ protected String id; protected String[] details } I have a destination class that looks like this: public class initResponse{ protected String id; protected DetailsObject detObj; } public class DetailsObject{ protected List<String> details; } So essentially i want the string in the details array to be populated into the List in the Details object. I have tried a mapping

JAXB should ignore element

偶尔善良 提交于 2020-02-05 07:14:18
问题 The structure <html> <span><h1>test</h1></span> <table> </table> </html> How can i get the text "test" if <span> might be a <div> ? @XmlAccessorType(XmlAccessType.FIELD) public class HtmlTag { @XmlElement(name = "h1") String h1; } Unmarshalls to null. 回答1: @XmlAccessorType(XmlAccessType.FIELD) public class HtmlTag { @XmlAnyElement List<org.w3c.dom.Element> elements; } get test string HtmlTag htmlTag = //... Element firstElement = htmlTag.elements.get(0); // this is first element, // currently

JAXB attribute with Object type throwing null pointer exception?

假如想象 提交于 2020-02-03 05:17:47
问题 I am trying to annotate a java class to create a JAXB schema with an element that has an attribute of value. The code is below: @XmlAttribute(name="value") public Object getSettingValue() { return this.settingValue; } public void setSettingValue( final Object settingValue ) { this.settingValue = settingValue; } When I try to generate the schema (using Eclipse's non-Moxy implementation), I get this null pointer exception: Exception in thread "main" java.lang.NullPointerException at com.sun.xml

Mule JaxB binding error - “package” doesnt contain ObjectFactory.class or jaxb.index

…衆ロ難τιáo~ 提交于 2020-01-25 01:52:20
问题 I am using mule with maven. I have used a xml to object converter. My model files are annotated with jaxb annotations. The JAXB context ref looks like this -: mulexml:jaxb-context name="JAXB_Context" packageNames="com.xml.model" doc:name="JAXB Context"/> I have created a jaxb.index file with the names of the JAXB annotated classes and placed in the com.xml.model folder. But still it shows the following exception -: org.springframework.beans.factory.BeanCreationException: Error creating bean

Jaxb Marshals the same XML Message

▼魔方 西西 提交于 2020-01-24 21:47:05
问题 I am using Jaxb for marshalling and unmarshalling objects. This is the code of my custom class for the purpose. import test.org.swt.SwitchMsg; import test.org.swt.TrxMsg; import org.springframework.context.annotation.Configuration; import org.springframework.xml.transform.StringSource; import javax.annotation.PostConstruct; import javax.xml.bind.*; import java.io.StringWriter; @Configuration public class JaxbConfig { private JAXBContext jaxbContext; @PostConstruct private void init(){ try {

Glassfish XML (or JSON) Response for JAX-RS Object Marshalling Results in HTTP 500 Internal Server Error

不羁的心 提交于 2020-01-24 16:32:05
问题 I am trying to get a JAX RS resource to return a response with a JSON object. When I display the response properties via println() calls in the resource class I see that the MediaType is correctly set to "application/json", that there is an entity associated with the response with the expected type (SalesOrder), status (Status.FOUND) and that the response object is an instance of OutboundJaxrsResponse. But somehow when the browser (or a Jersey client) receives the response, these response

Filtering out elements based on sub elements with XMLStreamReader and StreamFilter

独自空忆成欢 提交于 2020-01-24 15:36:09
问题 I want to do something similar to XMLStreamReader example @BlaiseDoughan gave in his response to JAXB filtered parsing however I need to make the filtering decision based on sub elements not current node attributes. XMLStreamReader does not have a peek API like XMLEventReader. For example, I want to unmarshall the following XML into a Gump object whose records list ends up only containing 1 item, the record whose associated name does not start with "Filtered-". I'm using Eclipselink 2.3

Filtering out elements based on sub elements with XMLStreamReader and StreamFilter

半城伤御伤魂 提交于 2020-01-24 15:36:08
问题 I want to do something similar to XMLStreamReader example @BlaiseDoughan gave in his response to JAXB filtered parsing however I need to make the filtering decision based on sub elements not current node attributes. XMLStreamReader does not have a peek API like XMLEventReader. For example, I want to unmarshall the following XML into a Gump object whose records list ends up only containing 1 item, the record whose associated name does not start with "Filtered-". I'm using Eclipselink 2.3