Skip to main content

unmarshaller gives empty java object

1 reply [Last post]
yvilke
Offline
Joined: 2005-07-25
Points: 0

Hello,

I have a problem when I try to unmarshal XML to Java.
I first created my java files throught a XML schema:

And then I used the objects to marshal data into xml.
Marshalling works fine but unmarshalling don't.

I use this object for unmarshalling:

package marshalling;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.rmi.MarshalException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import addressBook.Global;
import addressBook.model.generated.ClientsList;

public class ConvertXMLToJava {

public ConvertXMLToJava()
throws FileNotFoundException, MarshalException,
JAXBException
{

JAXBContext jc = JAXBContext.newInstance( Global.JAXB_PACKAGE,
this.getClass().getClassLoader());

// Create the unmarshaller
Unmarshaller unmarshaller = jc.createUnmarshaller();

// Unmarshal the object
JAXBElement list = (JAXBElement) unmarshaller.unmarshal(getFileStream());

Marshaller m = jc.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.marshal( list, System.out );

}

private FileInputStream getFileStream(){
try{
return new FileInputStream(Global.XML_OUTPUT_FILE);
}catch(FileNotFoundException e){
e.printStackTrace();
return null;
}
}
}

This is the only thing I get if I unmarshall the XML file:

Convert XML to Java!
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Can anybody help me please?

Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09
Points: 0

When you are suspecting a bug and posting long code/xml fragments like this, please consider using the issuetracker at http://jaxb.dev.java.net/

Between the stripping of indentation, use of emoticon, and etc, this forum isn't a good place to do a trouble-shooting.