UnknownFieldException - 没有这样的字段 [英] UnknownFieldException - No such field

查看:49
本文介绍了UnknownFieldException - 没有这样的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 xstream 将 xml 文件编组到 POJO 中时,我不断收到此错误,我不确定发生了什么,可以用全新的眼光看待事物.

I keep getting this error when I try to marshall an xml file into POJO's using xstream, im not sure what is going on , could do with a fresh eye to look at things.

Exception in thread "main"      com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.smurk.webtest.domain.Attribute.class-title
---- Debugging information ----
field               : class-title
class               : org.smurk.webtest.domain.Attribute
required-type       : org.smurk.webtest.domain.Attribute
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /classification/attributes/attribute/class-title
line number         : 1
class[1]            : org.smurk.webtest.domain.Attributes
class[2]            : org.smurk.webtest.domain.Classification
version             : 1.4.6
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:495)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:351)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1157)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1141)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1012)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1003)
at org.smurk.webtest.XmlRead.parseFile(XmlRead.java:31)
at org.smurk.webtest.Main.main(Main.java:15)

这些是相关的域对象:

@XStreamAlias("attribute")
public class Attribute {

    @XStreamAlias("class-title")
    private ClassTitle classTitle; 

    @XStreamAlias("type")
    private String type;

    public ClassTitle getClassTitle() {
        return classTitle;
    }

    public void setClassTitle(ClassTitle classTitle) {
        this.classTitle = classTitle;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}

@XStreamAlias("class-title")
public class ClassTitle {

    @XStreamAlias("title-part")
    private TitlePart titlePart;

    public TitlePart getTitlePart() {
        return titlePart;
    } 

    public void setTitlePart(TitlePart titlePart) {
        this.titlePart = titlePart;
    }

}

这是xml:

<classification symbol="A01B1/00" level="7" additional-only="false" status="PUBLISHED">
<attributes>
    <attribute type="TITLES">
        <class-title>
            <title-part>
                <text scheme="ipc">Hand tools</text>
                <explanation>
                    <text scheme="ipc"> edge trimmers for lawns <class-ref scheme="cpc">A01G3/06</class-ref> ; </text>
                    <comment>
                        <text scheme="cpc"> machines for working soil <class-ref scheme="cpc">A01B35/00</class-ref> ; making hand tools <class-ref scheme="cpc">B21D</class-ref>
                        </text>
                    </comment>
                </explanation>
            </title-part>
        </class-title>
    </attribute>
</attributes>
</>

推荐答案

只是为了回答这个问题,我在父类中似乎有一些 XStream 注释错误,这导致了层次结构的进一步错误.

Just to answer the question, it seems I had some XStream annotation wrong in a parent class, this was causing an error further down the hierarchy.

这篇关于UnknownFieldException - 没有这样的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆