XStream转换异常:编组被拒绝

时间:2017-12-13 04:28:08

标签: java javafx xstream

我在序列化时遇到以下错误:

  

com.thoughtworks.xstream.converters.ConversionException:安全性   警报。编组被拒绝了。

我的代码如下;错误在标记的行上。

public class SerializeVisitor implements Visitor {

public static final String ID = "id";
private XStream serializer = new XStream(new DomDriver());
private Map<String, String> data = new HashMap<String, String>();

/**
 * @see Visitor#visit(Visitee)
 *
 * @param v the object to be visited, must implement the Visitee interface. Normally passed a reference to this,
 */
@Override
public void visit(Visitee v) {
    try {
        Field f = v.getClass().getDeclaredField(DATA_UTIL.getString(ID));
        if(!f.isAccessible()) f.setAccessible(true);
        String id = (String) f.get(v);
        System.out.println(id);
        String serialized = serializer.toXML(v); //ERROR HERE
        data.put(id, serialized);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
        DialogFactory.showError(String.format(StartView.getErrorBundle().getString(AuthoringVisitor.XML_SV_ERR), v.getClass().toString()));
    }
}

/**
 * Clear the map and return the old value stored inside it. The map should only ever be one entry long, since this will
 * visit one object at a time before returning to the dispatching object.
 *
 * @return The class name of the serialized object and the serialized representation of that object
 */
@Override
public Map<String, String> getStateFromVisit() {
    return data;
}
}

这是堆栈跟踪的第一部分:

at com.thoughtworks.xstream.XStream$InternalBlackList.marshal(XStream.java:2550)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:274)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:250)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:213)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:144)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)

知道可能导致这种情况的原因是什么?谢谢!

编辑:上面添加了更多代码

0 个答案:

没有答案