weixin_41283258 2018-03-20 06:29 采纳率: 0%
浏览 1080
已采纳

关于JAXB xml转对象失败

@XmlRootElement(name="interfaceContainer")
public class InterfaceContainer {
//接口名
private String interfaceName;
//接口方法
private List methods;
//接口描述
private String comment;
//接口创建人
private String creator;
//接口创建时间
private Date createDate;
//接口修改人
private String modifier;
//修改时间
private Date updateDate;
//生成时间
private Date generatedDate;
//状态
private int state;
//get set
@XmlElement
public String getInterfaceName() {
return interfaceName;
}

public void setInterfaceName(String interfaceName) {
    this.interfaceName = interfaceName;
}
@XmlElementWrapper(name = "methods")
@XmlElement(name = "method")
public List<MethodContainer> getMethods() {
    return methods;
}
public void setMethods(List<MethodContainer> methods) {
    this.methods = methods;
}
@XmlElement
public String getComment() {
    return comment;
}
public void setComment(String comment) {
    this.comment = comment;
}
@XmlElement
public String getCreator() {
    return creator;
}
public void setCreator(String creator) {
    this.creator = creator;
}
@XmlElement
public Date getCreateDate() {
    return createDate;
}
public void setCreateDate(Date createDate) {
    this.createDate = createDate;
}
@XmlElement
public String getModifier() {
    return modifier;
}
public void setModifier(String modifier) {
    this.modifier = modifier;
}
@XmlElement
public Date getUpdateDate() {
    return updateDate;
}
public void setUpdateDate(Date updateDate) {
    this.updateDate = updateDate;
}
@XmlElement

public Date getGeneratedDate() {
    return generatedDate;
}
public void setGeneratedDate(Date generatedDate) {
    this.generatedDate = generatedDate;
}
@XmlElement
public int getState() {
    return state;
}

public void setState(int state) {
    this.state = state;
}

这个是最外层的对象,

public class MethodContainer {
//方法名称
private String methodName;
//方法参数
private List param;
//方法返回值
private ParamMethod returned;
//方法修饰词
private String decorated;
//方法体
private String methodBody;
//get set方法
@XmlElement
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
@XmlElementWrapper(name = "params")
@XmlElement(name = "param")
public List getParam() {
return param;
}
public void setParam(List param) {
this.param = param;
}
@XmlElement
public String getDecorated() {
return decorated;
}
public void setDecorated(String decorated) {
this.decorated = decorated;
}
@XmlElement
public ParamMethod getReturned() {
return returned;
}
public void setReturned(ParamMethod returned) {
this.returned = returned;
}
@XmlElement
public String getMethodBody() {
return methodBody;
}
public void setMethodBody(String methodBody) {
this.methodBody = methodBody;
}

这个是中间对象

@XmlRootElement(name="interfaceContainer")
public class ParamMethod {
//参数类型

private String paramClazz;
//参数名

private String paramName;
//get  set
@XmlElement
public String getParamClazz() {
    return paramClazz;
}
public void setParamClazz(String paramClazz) {
    this.paramClazz = paramClazz;
}
@XmlElement
public String getParamName() {
    return paramName;
}
public void setParamName(String paramName) {
    this.paramName = paramName;
}

这个是底层对象 ,

java.lang.ClassCastException: com.entity.ParamMethod cannot be cast to com.entity.InterfaceContainer

这个是异常

  • 写回答

1条回答 默认 最新

  • a15230279079 2018-03-21 08:41
    关注

    这个是中间对象
    @XmlRootElement(name="interfaceContainer")
    public class ParamMethod {

    异常说的是这里没法转换成element 'interfaceContainer',建议去掉再试试

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 网页游戏在本地页面修改游戏结果
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数