Using JAXB with JgraphX?

330 views Asked by At

I have some entities mapped with JAXB annotations to turn them into xml, but within those entities mxCell there is an object, how can I map this object without adding annotations in the code library JgraphX​​?

There is my Objeto class:

@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso({mxCell.class})
public abstract class ObjetoImpl implements Serializable, Objeto {

    @XmlAttribute
    protected String nome;

    @XmlAnyElement    
    protected mxCell cell;


    @Override
    public String toString() {
        return this.nome;
    }
}

It's give me the following exception:

 com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
com.mxgraph.model.mxICell is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at com.mxgraph.model.mxICell
        at public com.mxgraph.model.mxICell com.mxgraph.model.mxCell.getParent()
        at com.mxgraph.model.mxCell
        at @javax.xml.bind.annotation.XmlSeeAlso(value=[class com.mxgraph.model.mxCell])
        at ardis.model.conceitual.atributo.Atributo
        at protected java.util.List ardis.model.conceitual.ObjetoWithAttributeImpl.attributes
        at ardis.model.conceitual.ObjetoWithAttributeImpl
        at ardis.model.conceitual.entidade.Entidade
        at @javax.xml.bind.annotation.XmlSeeAlso(value=[class ardis.model.conceitual.entidade.Entidade])
        at ardis.model.conceitual.ModeloConceitual

That exception occurs when the implementation of the interface is not correctly mapped with Jaxb, but i don't want enter into the jgraphx library and modify it

2

There are 2 answers

0
Davisson Paulino On BEST ANSWER

I could not convert the objects of the program who had a mxCell inside using JAXB, so the solution for me was use the JgraphX "getXml" to convert the graph elements and the values of each cell. After that I get the value of the cells and use at my code.

The code to pass the graph to xml:

        mxCodec codec = new mxCodec();


    String xml = mxXmlUtils.getXml(codec.encode(graph.getModel()));
0
bdoughan On

There are a couple of ways that you can handle this use case:


Option #1 - Specify the Impl Class with @XmlElement

For fields/properties that are of an interface type can use the @XmlElement annotation to specify the concrete implementation.

@XmlElemen(type=mxCellImpl.class)    
protected mxCell cell;

For More Information


Option #2 - Use an XmlAdapter

An XmlAdapter allows you to convert an unmappable object to a mappable one during the marshalling/unmarshalling process. You could use this to convert JgraphX into your own domain object.

For More Information