jaxb

How to set the default namespace using JAXB

霸气de小男生 提交于 2020-01-21 11:35:08
问题 I have a ATOM-XML representation of my data that is returned via a Spring MVC web service. I'm using JAXB to do the serialization, I have a number of namespaces but I want the default namespace set to Atom with no prefix. Here is what I have so far in package-info.java but the atom prefix is being set to ns3. @XmlSchema(namespace = com.mycomponay.foo.ATOM_NAMESPACE, xmlns = { @XmlNs(prefix = "foo", namespaceURI = com.mycomponay.foo.NAMESPACE_FOO), }, elementFormDefault = javax.xml.bind

Print Jersey JSON in Unit Testing

隐身守侯 提交于 2020-01-21 11:17:42
问题 Is there any plain way to print a JAXB annotated instance in JSON format (as exactly jersey will print in AS) while running unit testing without any embedded server launched? I can run and see in XML with JAXBContext, Marshaller, and so on. Is there any example for JSON? I found it. It's similar to JAXB. With Jersey API final JSONJAXBContext context = new JSONJAXBContext(...); final JSONMarshaller marshaller = context.createJSONMarshaller(); marshaller.marshallToJSON(...); final

How to create Java objects from XML tags which are referring each other?

为君一笑 提交于 2020-01-21 05:05:07
问题 I have an XML which has tags corresponding to three types of Java objects which would be created from the XML. The objects are of the form: A - static Map<String, A> - String name - String aInfo1 - String aInfo2 B - static Map<String, B> - String name - String bInfo1 - String bInfo2 C - A aObject - B bObject Now, in my XML, I define a list of tags for A objects and B objects and then I define tags for C objects which refer to A and B objects using there name field. I have two requirements:

Validate xml created using jaxb against an xsd file

半城伤御伤魂 提交于 2020-01-21 01:44:37
问题 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. 回答1: 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

Validate xml created using jaxb against an xsd file

风流意气都作罢 提交于 2020-01-21 01:44:06
问题 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. 回答1: 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

Can one validate marshalled XML with JAXB 2.0?

被刻印的时光 ゝ 提交于 2020-01-20 17:00:25
问题 Apparently in version 2 of JAXB - the validator class has been deprecated - does this mean the marshaller is automatically validating your XML? If so it doesn't seem to be complaining about some of the incorrect XML I am forming! Can anyone give me some advice on how I can validate marshalled XML to make sure it conforms to the XSD schema. Many thanks. 回答1: Validation capabilities have been expanded in JAXB 2.0 through the use of the JAXP 1.3 Schema Validation Framework. Where before you did:

Can one validate marshalled XML with JAXB 2.0?

放肆的年华 提交于 2020-01-20 16:57:31
问题 Apparently in version 2 of JAXB - the validator class has been deprecated - does this mean the marshaller is automatically validating your XML? If so it doesn't seem to be complaining about some of the incorrect XML I am forming! Can anyone give me some advice on how I can validate marshalled XML to make sure it conforms to the XSD schema. Many thanks. 回答1: Validation capabilities have been expanded in JAXB 2.0 through the use of the JAXP 1.3 Schema Validation Framework. Where before you did:

getting Dynamic attribute for element in Jaxb

狂风中的少年 提交于 2020-01-20 08:09:56
问题 I have the following XML tag with many attributes. The number/name of the attributes is not given because I am getting the XML in runtime and I just know the name of the tag. How can I use JAXB to get all the attribute as a Map<String, String> ? How can I add this to the following Java code: import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement;

Parsing XML for deeply nested data

时光怂恿深爱的人放手 提交于 2020-01-17 08:33:32
问题 I have an XML file that is structured something like this: <element1> <element2> <element3> <elementIAmInterestedIn attribute="data"> <element4> <element5> <element6> <otherElementIAmInterestedIn> <data1>text1</data1> <data2>text2</data2> <data3>text3</data3> </otherElementIAmInterestedIn> </element6> </element5> </element4> </elementIAmInterestedIn> <elementIAmInterestedIn attribute="data"> <element4> <element5> <element6> <otherElementIAmInterestedIn> <data1>text1</data1> <data2>text2<

Maven build of annotated JAXB 2.2.4-1 Web Service fails with JDK 1.6

非 Y 不嫁゛ 提交于 2020-01-17 05:16:27
问题 Using Maven 3.0.3 to build a web service using JAXB (2.2.4-1) and CXF 2.4.2 fails with the following error: org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project cxfmaventest: Compilation failure /Users/ksuda/Documents/workspace/cxfmaventest/src/main/java/cxfmaventest/CXFMavenTest.java:[18,83] annotation type not applicable to this kind of declaration The line that fails contains