【问题标题】:EclipseLink: "Missing class for indicator field value" without inheritanceEclipseLink:没有继承的“指标字段值的缺失类”
【发布时间】:2016-02-17 14:05:06
【问题描述】:

我在使用 Moxy 将 JSON 字符串转换为 XML 对象时遇到问题。 这是我进行此转换时遇到的异常:

Exception [EclipseLink-43] (Eclipse Persistence Services - 2.6.2.v20151217-774c696): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [TENANT] of type [class java.lang.String].
Descriptor: XMLDescriptor(fr.niji.nates.webservices.macd.ws.COMPONENTTYPE --> [])
    at org.eclipse.persistence.exceptions.DescriptorException.missingClassForIndicatorFieldValue(DescriptorException.java:940)
    at org.eclipse.persistence.internal.oxm.QNameInheritancePolicy.classFromRow(QNameInheritancePolicy.java:278)
[...]

这是 COMPONENTTYPE 类:

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "COMPONENT_TYPE")
@XmlSeeAlso({
    COMPONENTDETAILTYPE.class,
    MACDRESULTTYPE.Created.class
})
public class COMPONENTTYPE {

    @XmlAttribute(name = "type", required = true)
    protected String type;
    @XmlAttribute(name = "dbid", required = true)
    protected int dbid;

    public String getType() {
        return type;
    }

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

    public int getDbid() {
        return dbid;
    }

    public void setDbid(int value) {
        this.dbid = value;
    }
}

问题似乎只出在“类型”属性上。

有人有想法吗? 谢谢,

【问题讨论】:

  • 属性@type 用于“classIndicatorField”。所以在 QNameInheritancePolicy.classFromRow 方法中,'lineObject indicator = rowFromDatabase.get(getClassIndicatorField());'返回结果而不是“null”......有没有解决方案可以忽略这个?

标签: eclipselink moxy


【解决方案1】:

我找到的解决方案是在类中添加注解@XmlDiscriminatorNode:

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;

import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorNode;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "COMPONENT_TYPE")
@XmlSeeAlso({
    COMPONENTDETAILTYPE.class,
    fr.niji.nates.webservices.macd.ws.MACDRESULTTYPE.Created.class
})
@XmlDiscriminatorNode("@@type")
public class COMPONENTTYPE {
    [...]

【讨论】:

    猜你喜欢
    • 2016-01-11
    • 2014-11-04
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2022-06-22
    相关资源
    最近更新 更多