jaxb « Development « Java I/O Q&A





1. JAXB: How to ignore namespace during unmarshalling XML document?    stackoverflow.com

My schema specifies a namespace, but the documents don't. What's the simplest way to ignore namespace during JAXB unmarshalling (XML -> object)? In other words, I have

<foo><bar></bar></foo>
instead of,
<foo xmlns="http://tempuri.org/"><bar></bar></foo>

2. Custom serialization in JAXB    stackoverflow.com

Is there a way to customize XML serialization in JAXB, in the same way that it's possible using IXmlSerializable in .NET? (i.e. the ability to directly control serialization of an object ...

3. validating JAXB, but whitespace not ignored    stackoverflow.com

some code snippets. The java coding doing the jaxb unmarshaling. pretty straightforward, copied out of tutorials online.

JAXBContext jc = JAXBContext.newInstance( "xmlreadtest" );
Unmarshaller u = jc.createUnmarshaller();

// setting up for validation.
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource ...

4. How do you serialize an Exception subclass in JAXB?    stackoverflow.com

How do you serialize a subclass of Exception? Here is my exception:

@XmlType
public static class ValidationFault extends Exception {
 public ValidationFault() {

 }
}
I have tried all sorts of variations on using ...

5. What is the Jaxb equivalent of a CData Block?    stackoverflow.com

I am looking to convert a class that looks like this ...

public class Amenity {
   public String id;
   public String value;
}
into the following XML using JaxB annotations:
<amenity ...

6. Can I force JAXB not to convert " into ", for example, when marshalling to XML?    stackoverflow.com

I have an Object that is being marshalled to XML using JAXB. One element contains a String that includes quotes ("). The resulting XML has &quot; where the " ...

7. How to generate a Java class which implements Serializable interface from xsd using JAXB?    stackoverflow.com

I would like to introduce caching into an existing Spring project which uses JAXB to expose WebServices. Caching will be done on the level of end points. In order to do ...

8. xjc binding file for throws error    stackoverflow.com

I have xsd defination

<element name="primaryKey" nillable="false">
   <complexType mixed="false">                   
 ...

9. how generate javaDoc from a jaxb file    stackoverflow.com

i am working with Jaxb. and i would like to generate javaDoc files from these classes, is it the same way as i would do it to a regular java files? ...





10. how can i unmarshall in jaxb and enjoy the schema validation without using an explicit schema file    stackoverflow.com

I am using jaxb for my application configurations I feel like I am doing something really crooked and I am looking for a way to not need an actual file or this ...

11. In generated code, how to access the facets declared in the XSD file?    stackoverflow.com

What I thought was going to be a simple problem turns out to be quite a head scratcher. I am currently using JAXB 2 to generate code from an XSD on which ...

12. Trimmed down JAXB for just unmarshalling?    stackoverflow.com

I'm building an application where space is at a premium. I'd really like to use JAXB's unmarshalling capabilities, but including the whole library is out of the question. Has anyone pared ...

13. Choosing framework for XML persistency    stackoverflow.com

I need to choose a framework for XML persistency of some java classes in our application. My requirements are: 1. I start from java classes, not from schema 2. Using annotations for customization 3. Ability ...

14. Ignore a parent class when Serializing to XML    stackoverflow.com

Is there a JAXB annotation to ignore a parent class, when you have an @XmlElement on a List of the child classes? Just to clarify - I was wondering if there was ...

15. @XmlRootElement and throws IllegalAnnotationExceptions    stackoverflow.com

When I marshall an instance of this class ...

@XmlRootElement
public static class TestSomething<T extends Serializable> {

    T id;

    public T getId() {
     ...

16. Java xml serialization null handling    stackoverflow.com

I am using JAXB2 to serialize object to xml. Is there any way how to force it to create entire object structure like in following example even if it is not ...





17. Can JAXB store the class name in the XML so that the the deserialize code doesn't need knowledge of the class?    stackoverflow.com

It seems the standard approach for deserializing JAXB XML is to specify the package name when creating the context. Then, JAXB looks up the class based on the root element: JAXBContext ...

18. Providing custom value serialization for enums via JAXB    stackoverflow.com

For a project I'm working on, we have a lot of enums in use. The model object itself is composed from a lot of tiny classes; this model we then serialize ...

19. How to convert Date(ActionScript 3) to java.util.Date through a xml?    stackoverflow.com

I want to convert Date(ActionScript 3) to java.util.Date through a xml. First, write a user defined ActionScript class like this.

public class User
{
    public function User()
    {
 ...

20. Using XML annotations    stackoverflow.com

I have (inherited) an application that is configured by XML file. When the application starts it instantiates its configuration from the file with a bunch of annotated objects. So I have ...

21. JAXB Annotations    stackoverflow.com

I need a little help with JAXB Annotations and I couldn't find good doc's helping me figure this out. I have a class that I want to marshal into XML. My Class ...

22. how to serialize and de-serialize objects using JAXB?    stackoverflow.com

i have an issue.. i want to convert an object into another object using JAXB. As in, i have a class com.home.Student, and another class com.school.Student, both have same arguments, infact ...

23. What's the most standard Java way to store raw binary data along with XML?    stackoverflow.com

I need to store a huge amount of binary data into a file, but I want also to read/write the header of that file in XML format. Yes, I could just store ...

24. JAXB binding file: XmlAdapters and package name    stackoverflow.com

I have a binding file like this

<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <jxb:bindings schemaLocation="example.xsd" node="/xs:schema">
    <jxb:schemaBindings>
        <jxb:package name="example" />
    ...

25. Order xml superclass elements in Java serialization    stackoverflow.com

I have to classes ParentClass and ChildClass in JAVA using JAXB. ChildClass extends ParentClass. When I serialize an object of ChildClass, in the resulting XML, ParentClass properties appear first, I would like to ...

26. Invalid XML Character During Unmarshall    stackoverflow.com

I am marshalling objects to XML file using encoding "UTF-8". It generates file successfully. But when I try to unmarshal it back, there is an error:

An invalid XML character ...

27. JAXB, how to skip class tag when included    stackoverflow.com

I'm trying to get that XML:

<person>
    <foo>thing</foo>
    <bar>other</bar>
</person>
from that code
public class Person {
    private InnerThing in;
}

public class InnerThing {
    ...

28. Need to generate JAXB annotions in package-info.java from binding file    stackoverflow.com

I have an annotation for an XmlAdapter that I need to put in package-info.java.. The problem is, our package-info.java is automatically generated from XJC. Is there a way to use the ...

29. Serialize a Java Object    stackoverflow.com

Let me know the best way to serialize my Java object Download. This is a class generated from a java wsimport tool from a WSDL.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Download", propOrder = {
 ...

30. @XmlElements marked with @XmlJavaTypeAdapters?    stackoverflow.com

I have this situation

@XmlType(name ="", propOrder={"value"})
@XmlRootElement(name = "compound")
public class Compound extends Value {
  @XmlElements({
  @XmlElement(name="simple", type=Simple.class),
  @XmlElement(name="compound", type=Compound.class)
  })
  protected List<Value> value;
  // ...
}
So a ...

31. jaxb create xml attribute    stackoverflow.com

I want to create xml from my object, but instead of xml nodes I'd like to create attribute i.e.

@XmlRootElement
class MyObject{
 private String name;
 private String age;
 ...getters/setters...
}
And I want my object ...

32. JAXB cannot locate a file from a relative path    stackoverflow.com

I'm trying to use Jaxb in order to unamrshal an xml file. for some reason that I don't understand, I cannot refer to any other location then a full path on ...

33. ANT & JAXB: add "extension" and make generated classes "serializable"    stackoverflow.com

this is my first post in this great community. I am trying to generate beans classes using JAXB and Ant This is my code:

    <target name="generation beans" description="generation des beans ...

34. How to change programmatically the default JAXB date serialization?    stackoverflow.com

Is there a way to change the default way jaxb serialize/deserialize types, dates in my case, without specifying it through annotation and/or through xml jaxb binding as mentioned here http://jaxb.java.net/guide/Using_different_datatypes.html I'd ...

35. XmlSerialize 3rd-party class using JAXB    stackoverflow.com

The reading that I've done thus far on JAXB suggests that its usage is limited to serializing classes that one can annotate properly (i.e. one has the class' source). Is there a ...

36. How to generate XSD for JaxB Java files in IntelliJ    stackoverflow.com

Is there an easy way to do this. I have some classes annotated with

@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
I am trying to lookup at the same time on internet.

37. How to partially marshall/unmarshall an object?    stackoverflow.com

I have a class A with attributes B b and C c that I want to marshall and unmarshall in a way that in c instead of having an java object ...

38. How to override the default name for in JAXB using a external binding file?    stackoverflow.com

I have an element that looks something like this.

 <xsd:element name="container">
    <xsd:complexType>
      <xsd:choice minOccurs="0" maxOccurs="unbounded">
        <xsd:element ...

39. JAXB location in file for unmarshalled objects    stackoverflow.com

I have some objects being unmarshalled from an XML file by JAXB. Is it possible to have JAXB tell me or somehow find out where in the XML file (line and ...

40. How to get values from enclosing elements in JAXB    stackoverflow.com

I have the following XML structure:

<PriceBook>
    <PriceList product="0D000000.007C.06">
        <Price .../>
        <Price .../>
   ...

41. Making data model classes serializable    stackoverflow.com

I am using JiBX for XML-Java data binding. The current configuration generates classes pretty well but I want these generated classes to implement java.io.Serializable. Here is maven plugin configuration to generate ...

42. JAXB - How to set the xsi:type of a XML element based on its value?    stackoverflow.com

I have to generate a xml element that can have as value any "primitive type" (xsd:string, xsd:boolean, etc). Examples:

<field xsi:type="xsd:string" name="aString">String Value</field>
<field xsi:type="xsd:date" name="aDate">2011-10-21</field>
...
So, I tried two implementations:
public class Field ...

43. Maintain directory hierarchy when converting from XSD to JAVA Class?    stackoverflow.com

I have a set of XSD Schemas , that are present in a directory structure . I am using JAXB to convert it into Java Classes . Now when converting it ...

44. Unmarshalling using JAXB    stackoverflow.com

I am new to java (coming from c#.net background) and was trying the above example to marshal and unmarshal. Following the link below Marshalling a List of objects with JaxB using the above ...

45. How to read and write XML elements "as is" with JAXB?    stackoverflow.com

I have to process some "ugly" XML pieces and would like to do so using JAXB to save some time. Let's say my documents are structured like this:

<root a="1" b="2" c="3">
<header a="1" ...

46. How to marshall or serialize objects to XML without using Jaxb?    coderanch.com

Hi all, I use Axis to create java classes based on a WSDL. After I fill or set values to the classes by using the setters, I want to marshall the objects to XML. I know I can simply use Jaxb to do this. But since I will deploy my application to BEA Weblogic 8 and this is not compatible with ...

47. How to create a JAXB Context from File System    coderanch.com

Hi I was writing an unmarshaller for JAXB, but for that first I need to create a JAXB Context. Here is the sample code I am using import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.UnmarshalException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; ...