Badisi
Badisi

Reputation: 519

Ignore SuperClass

I'm using a class that extends a JavaFx's component

public class MyClass extends Pane {}

I want to serialize that class only and not the Pane superclass.

As Jaxb does not support it, I'm using Eclipselink MOXy to achieve that:

marshaller

Map<String, Source> metadataSource = new HashMap<String, Source>();
metadataSource.put("com.myapp", new StreamSource(getClass().getResourceAsStream("/com/myapp/myclass.xml")));

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSource);

JAXBContext context = JAXBContext.newInstance(new Class[] {MyClass.class}, properties);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(new MyClass(), new File("test.xml"));

myclass.xml

<?xml version="1.0"?>
<xml-bindings 
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    version="2.3">
    <java-types>
        <java-type name="javafx.scene.layout.Pane" xml-transient="true" />
    </java-types>
</xml-bindings>

But i'm getting this error :

javax.xml.bind.JAXBException:  Exception Description: The java-type with package [javafx.scene.layout] is not allowed in the bindings file keyed on package [com.myapp]. - with linked exception: [Exception [EclipseLink-50037] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.JAXBException

I've spent hours to find some information but found none..

Any help would be appreciated !

Thanks

Upvotes: 2

Views: 469

Answers (1)

bdoughan
bdoughan

Reputation: 149007

You could use MOXy's external mapping document to specify that the super type is java.lang.Object instead of Pane.

<?xml version="1.0"?>
<xml-bindings 
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="com.example">
    <java-types>
        <java-type name="MyClass" super-type="java.lang.Object"/>
    </java-types>
</xml-bindings>

Answer to Related Question

Upvotes: 1

Related Questions