moxy

How to know what JAXB implementation is used?

跟風遠走 提交于 2020-01-01 04:34:08
问题 I am using MOXy as JAXB Implementation but somehow I would like to show the Implementation Name (e.g. Moxy) and the version number on some admin screen (dynamically). How can I retrieve that info from JAXB? Cheers 回答1: You could do something like the following to figure out the JAXB impl being used: import javax.xml.bind.JAXBContext; public class Demo { private static final String MOXY_JAXB_CONTEXT = "org.eclipse.persistence.jaxb.JAXBContext"; private static final String METRO_JAXB_CONTEXT =

JAXB ignoring xml tag attribute

三世轮回 提交于 2019-12-31 03:00:29
问题 I read xml files with JAXB. I have the following structure <A> <B value="some string" /> </A> I have the following model @XmlRootElement class A{ @XmlElement(name = "B", required = true) @XmlPath("B/@value") String b; } I read the B tags value attribute in my b Instance variable. But in some XML files i have in the B tag following Structure <#B/> While JAXB unmarshall the files i become exception that the format is not correct. javax.xml.stream.XMLStreamException: ParseError at [row,col]:[19

Generation of XSD restrictions in a schema generated from Java JAXB annotated classes

∥☆過路亽.° 提交于 2019-12-30 09:37:10
问题 MOXy BeanValidation gives me the ability to add validation to my JAXB classes. Using MOXy's "Bean Validation Plugin" I can have Bean Validation in generated JAXB classes based on restrictions/facets from a prexisting Schema. However is there any way of generating a schema with restrictions/facetsbased on Bean Validation annotations from a JAXB annotated java class ? XJC has a handy plugin architecture when doing 'schema first' generating java, but is there any equivalent 'java first' way to

Using @XmlPath with jaxb/MOXy to map complex type

风流意气都作罢 提交于 2019-12-30 07:24:28
问题 I have a deep XML structure with a lot of pointless wrappers I'm mapping to a single Java class. Mapping the simple datatypes with @XmlPath is a walk in the park, but when it comes to types that actually require their own class I'm not quite sure how to do it, especially when those types should be put in a list as well. I'm having problems to map all the element types in the below example to my Element class. Since the elements wrapper resides in resource which is mapped using @XmlPath I can

JAXB: Represent nested Model Group Schema Components with a java object hierarchy

心不动则不痛 提交于 2019-12-25 06:07:49
问题 Schema allows a designer to specify optional sequences of child elements as follows; <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Schema1" xmlns:tns="http://www.example.org/Schema1" elementFormDefault="qualified"> <complexType name="RootType"> <sequence> <choice> <sequence minOccurs="1" maxOccurs="1"> <element name="A" type="tns:A"></element> <element name="B" type="tns:B"></element> <element name="C" type="tns

How do I mark fields as required/optional when reading XML with MOXy?

萝らか妹 提交于 2019-12-24 16:29:28
问题 Having a trivial code like this: @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) class A { @XmlPath("B/text()") private String b; @XmlPath("C/text()") private Integer c; ... } It works absolutely fine as long as I have apt values in my XML. I'd like to mark the field c as required, so MOXy throw every time I try to read the document where c is either not set, or invalid. What's the easiest solution? Update: Setting default values will also do. 回答1: EclipseLink JAXB (MOXy) or any JAXB

How to marshal/unmarshal a Map<Integer, List<Integer>>?

谁都会走 提交于 2019-12-24 13:26:09
问题 The following program marshals and unmarshals a class containing a Map<Integer, List<Integer>> field. After unmarshaling the list in the map contains strings and not integers. Is there an easy way to ensure that the list will be filled with integers instead of strings during unmarshalling? import java.io.StringReader; import java.io.StringWriter; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml

Discrepancy in marshal behaviour

纵饮孤独 提交于 2019-12-24 10:59:00
问题 I am testing MOXy 2.5.0 RC1. I marshalled the following to a string: <c r="C3" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <v>20</v> </c> It is represented by https://github.com/plutext/docx4j/blob/master/src/xlsx4j/java/org/xlsx4j/sml/Cell.java Notice the absence of any @XmlRootElement annotation With the reference implementation, the result, as expected, is: javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.internal.SAXException2: unable to

JAX-WS & JAX-RS with EclipseLink MOXy and external mapping documents

。_饼干妹妹 提交于 2019-12-24 10:37:36
问题 This is about using JAX-WS with EclipseLink MOXy and my problem of not being able to use MOXy's external mapping documents in this combination. (The same actually seems to apply to JAX-RS as well, but I'm limiting the details to JAX-WS to keep this from becoming even longer than it already is). I first describe (in some detail) the context of my requirements and the test code I've written to try and solve them. The actual question follows at the end of the post. The context: In some legacy

Spring MVC - set JAXB marshaller property when using @ResponseBody

本小妞迷上赌 提交于 2019-12-24 09:28:29
问题 I am trying to return a object from my controller which should be parsed to xml by spring. But I used the @XmlNamedObjectGraph (from moxy eclipselink) annotation in my class to customize the returned object. So I have to set the property MarshallerProperties.OBJECT_GRAPH from the marshaller. How can I access the marshaller, which is used by spring to parse my object, in my controller? ie: @RequestMapping(value = "/xml/", method = RequestMethod.GET, produces = "application/xml") @ResponseBody