jaxb2

Handling invalid enum values while doing JAXB Unmarshalling

折月煮酒 提交于 2019-11-30 13:07:38
My Jaxb has created a Enum class based on the XML schema set up. **enum Fruit { APPLE,ORANGE; }** I am using a SOAP UI to check my web service. Since it is a free form entry, if i give a wrong fruit say "Guva" then instead of throwing an exception it is returning it as null after doing the UnMarshalling. How can i avoid this? Should i use custom enum class instead of JAXB generated one. Please give some example. i.e. regards sri Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group. By default your JAXB (JSR-222) implementation will not fail on any

Returning JAXB-generated elements from Spring Boot Controller

混江龙づ霸主 提交于 2019-11-30 10:14:42
I'm generating a plethora of Java files from http://www.ncpdp.org 's XSD files (only available to members). After generating them, I'd like to use them in my Spring Controllers, but I'm having problems getting responses converted to XML. I've tried returning the element itself, as well as JAXBElement<T>, but neither seems to work. The test below fails: java.lang.AssertionError: Status Expected :200 Actual :406 @Test public void testHelloWorld() throws Exception { mockMvc.perform(get("/api/message") .accept(MediaType.APPLICATION_XML) .contentType(MediaType.APPLICATION_XML)) .andExpect(status()

Validate xml created using jaxb against an xsd file

故事扮演 提交于 2019-11-30 09:04:52
I have a xml file created using jaxb. I need to validate it against a xsd document. Is it possible to just do validation without unmarshalling. I need to then print the errors in the xml file. Forhad Yes you can use validator found in java from 1.5. here is the reference doc Apart from it you can use dom based or stream based API to validate your XML document against xsd file. If you wish to use SAX API for your task then hear is the example: try { String schemaLang = "http://www.w3.org/2001/XMLSchema"; SchemaFactory factory = SchemaFactory.newInstance(schemaLang); Schema schema = factory

Partial Unmarshalling of an XML using JAXB to skip some xmlElement

守給你的承諾、 提交于 2019-11-30 07:58:36
I want to unmarshal an XML file to java object using JAXB. The XML file is very large and contains some nodes which I want to skip in some cases to improve performance as these elements are non editable by client java program. A sample XML is as follows: <Example id="10" date="1970-01-01" version="1.0"> <Properties>...</Properties> <Summary>...</Summary> <RawData> <Document id="1">...</Document> <Document id="2">...</Document> <Document id="3">...</Document> ------ ------ </RawData> <Location></Location> <Title></Title> ----- // more elements </Example> I have two use cases: unmarshal into

Jaxb: How do I generate ObjectFactory class?

不问归期 提交于 2019-11-30 04:51:20
问题 I'm using Java 6, JaxB 2 and SpringSource Tool Suite (same as Eclipse). I had a couple of Java classes I wrote, from which I used JaxB to generate an XML schema. However, I'm noticing in order to use JaxB's ability to generate an XML document from Java objects, I need an ObjectFactory. final Marshaller marshaller = jaxbContext.createMarshaller(); // Here is where I don't have an ObjectFactory defined final JAXBElement<WebLeads> webLeadsElement = (new ObjectFactory()).createWebLeads

Unmarshalling nested list of xml items using JAXB

僤鯓⒐⒋嵵緔 提交于 2019-11-29 23:06:48
问题 I've got such xml construction which I need to convert into java objects using JAXB: <elements> <elemet> <type></type> <property1></property1> <property2></property2> <items> <item> <id></id> <name></name> </item> ... <item> <id></id> <name></name> </item> </items> </element> </elements> I should convert this construction not into element with nested list of items but into several elements one for every item. Here is example of Element class: class Element { Integer type; String property1;

Handling invalid enum values while doing JAXB Unmarshalling

泄露秘密 提交于 2019-11-29 18:32:50
问题 My Jaxb has created a Enum class based on the XML schema set up. **enum Fruit { APPLE,ORANGE; }** I am using a SOAP UI to check my web service. Since it is a free form entry, if i give a wrong fruit say "Guva" then instead of throwing an exception it is returning it as null after doing the UnMarshalling. How can i avoid this? Should i use custom enum class instead of JAXB generated one. Please give some example. i.e. regards sri 回答1: Note: I'm the EclipseLink JAXB (MOXy) lead and a member of

Returning JAXB-generated elements from Spring Boot Controller

我与影子孤独终老i 提交于 2019-11-29 15:17:55
问题 I'm generating a plethora of Java files from http://www.ncpdp.org's XSD files (only available to members). After generating them, I'd like to use them in my Spring Controllers, but I'm having problems getting responses converted to XML. I've tried returning the element itself, as well as JAXBElement<T>, but neither seems to work. The test below fails: java.lang.AssertionError: Status Expected :200 Actual :406 @Test public void testHelloWorld() throws Exception { mockMvc.perform(get("/api

Partial Unmarshalling of an XML using JAXB to skip some xmlElement

老子叫甜甜 提交于 2019-11-29 10:26:13
问题 I want to unmarshal an XML file to java object using JAXB. The XML file is very large and contains some nodes which I want to skip in some cases to improve performance as these elements are non editable by client java program. A sample XML is as follows: <Example id="10" date="1970-01-01" version="1.0"> <Properties>...</Properties> <Summary>...</Summary> <RawData> <Document id="1">...</Document> <Document id="2">...</Document> <Document id="3">...</Document> ------ ------ </RawData> <Location

why jaxb adapter annotation is not added to the proxy classes

元气小坏坏 提交于 2019-11-29 08:33:47
My XSD looks like this: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> ... <xs:element name="person"> <xs:complexType> ... <xs:attribute name="first_name" use="optional" type="xs:string"/> </xs:complexType> </xs:element> ... </xs:schema> I can't manage to add my adapter annotation to the concrete field ( generated proxy class must have my adapter annotation). So the result should be the following : @XmlJavaTypeAdapter(value=StringAdapter.class, type=String.class) @XmlAttribute(name = "first_name") protected String firstName; but my binding does not do