java-javafx.event.EventHandler是一个接口,JAXB无法处理接口

java-javafx.event.EventHandler是一个接口,JAXB无法处理接口,javafx,jaxb,Javafx,Jaxb,我有几节课。 其中一些 班级游戏 @XmlRootElement(name = "game") public class Game { private int scores = 0; private Field field; ... @XmlElement public int getScores() { return scores; } public void setScores(int scores) { this.scores = scores; } @XmlEl

我有几节课。 其中一些

班级游戏

@XmlRootElement(name = "game")
public class Game {
private int scores = 0;
private Field field;

...

 @XmlElement
public int getScores() {
    return scores;
}

public void setScores(int scores) {
    this.scores = scores;
}

@XmlElement
public Field getField() {
    return field;
}

public void setField(Field field) {
    this.field = field;
}


@XmlElement(name="NewShape")
public ArrayList<Shapes> getNewShapes() {
    return newShapes;
}

public void setNewShapes(ArrayList<Shapes> newShapes) {
    this.newShapes = newShapes;
}
...
}

当我尝试封送时,出现以下错误:

javafx.event.EventDispatcher是一个接口,JAXB无法处理接口。 此问题与以下位置有关: 在javafx.event.EventDispatcher上 在公共最终javafx.event.EventDispatcher javafx.scene.Node.getEventDispatcher()中 在javafx.scene.Node 在javafx.scene.shape.shape 在javafx.scene.shape.Rectangle 在private java.util.ArrayList graphic.Shapes.矩形中 在图形。形状 在private java.util.ArrayList game.game.newShapes 游戏,游戏

javafx.scene.input.InputMethodRequests是一个接口,JAXB不能 处理接口。此问题与以下位置有关: 在javafx.scene.input.InputMethodRequests公共决赛 javafx.scene.input.InputMethodRequests javafx.scene.Node.getInputMethodRequests()位于 javafx.scene.shape.shape位于javafx.scene.shape.Rectangle位于 私有java.util.ArrayList graphic.Shapes.矩形位于 private java.util.ArrayList game.game.newShapes中的graphic.Shapes 游戏,游戏

javafx.event.EventHandler是一个接口,JAXB无法处理 接口。此问题与以下位置有关:位于 公共最终javafx.event.EventHandler上的javafx.event.EventHandler javafx.scene.Node.getOnContextMenuRequested()位于javafx.scene.Node 位于javafx.scene.shape.shape处的javafx.scene.shape.矩形处的 私有java.util.ArrayList graphic.Shapes.矩形位于 private java.util.ArrayList game.game.newShapes中的graphic.Shapes 游戏,游戏

如果从类形状中删除元素组以进行编组,则不会出现错误。 我错过了什么?
谢谢。

您的组类必须是javafx.scene.Group类

资料来源:

正如您在oracle文档中看到的,该类从其超类继承了一定数量的属性,其中一些使用接口。JAXB不管理接口

不幸的是,如果希望将完整的组对象存储到XML,我看不到任何解决方案

但是,如果只希望整理某些属性(重新创建组对象所需的属性),则可以使用适配器仅保存这些属性

资料来源:


如果您选择适配器解决方案并需要帮助,请告诉我。

非常感谢。如果不是你,我早就想明白为什么会发生这种事了。
@XmlSeeAlso({RectangleVertic.class, RectangleHoriz.class, Square.class, Angle.class})
public abstract class Shapes {
    private double widthOfSquare, widthBetweenSquares, totalWidth, totalHeight;
    private int countOfSquaresInWidth, countOfSquaresInHeight;
    private ArrayList<Rectangle> rectangles= new ArrayList();
    private Group group;

public Shapes(){

}

public Shapes(double widthOfSquare, double widthBetweenSquares){
    this.widthOfSquare=widthOfSquare;
    this.widthBetweenSquares=widthBetweenSquares;
}


@XmlElement(type = Group.class)
public Group getGroup() {
    return group;
}

public void setGroup(Group group){
    this.group=group;
}

@XmlTransient
public double getWidthBetweenSquares() {
    return widthBetweenSquares;
}

@XmlTransient
public int getCountOfSquaresInWidth() {
    return countOfSquaresInWidth;
}

@XmlTransient
public int getCountOfSquaresInHeight() {
    return countOfSquaresInHeight;
}

@XmlTransient
public ArrayList<Rectangle> getRectangles() {
    return rectangles;
}

public void setRectangles(ArrayList<Rectangle> rectangles) {
    this.rectangles = rectangles;
}

@XmlTransient
public double getTotalWidth() {
    return totalWidth;
}

@XmlTransient
public double getTotalHeight() {
    return totalHeight;
}

@XmlTransient
public double getWidthOfSquare() {
    return widthOfSquare;
}

...

public abstract boolean putRectOnField(int startI, int startJ, ArrayList<Object[]> horizLinesOfSquare, ArrayList<Object[]> verticLinesOfSquare);
public abstract boolean checkPutRectOnField(int startI, int startJ, ArrayList<Object[]> horizLinesOfSquare, ArrayList<Object[]> verticLinesOfSquare);

public abstract int countOfShape();
public class JaxbParser implements Parser {
@Override
public Object getObject(File file, Class c) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(c);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    Object object = unmarshaller.unmarshal(file);
    return object;
}

@Override
public void saveObject(File file, Object o) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(o.getClass());
    Marshaller marshaller = context.createMarshaller();
    marshaller.marshal(o,file);
}