must implement java.io.Serializable 报错

博客记录了后台调用其他系统dubbo接口时出现的java.lang.RuntimeException异常,提示序列化类须实现java.io.Serializable。给出接口返回类型对象定义示例,指出原定义问题,展示修改后让内部类也实现该接口的代码,并提供参考链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 cause: java.lang.RuntimeException: Serialized class com.iboxchain.goodapay.dto.mcht.xxxx must implement java.io.Serializable
 Java field: private com.iboxchain.goodapay.dto.mcht.类对象$对象的内部类

com.iboxchain.goodapay.dto.mcht.类对象.对象的内部类
java.lang.RuntimeException: Serialized class com.iboxchain.goodapay.dto.mcht.TradeMchtQueryDto$SettleAccountInner must implement java.io.Serializable
 Java field: private com.iboxchain.goodapay.dto.mcht.TradeMchtQueryDto$SettleAccountInner com.iboxchain.goodapay.dto.mcht.TradeMchtQueryDto.settleAccount
 Java field: private java.util.List com.iboxchain.goodabase.common.dto.PageResultDto.list
    at com.alibaba.com.caucho.hessian.io.JavaSerializer$FieldSerializer.serialize(JavaSerializer.java:315)
    at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeInstance(JavaSerializer.java:263)

背景:

后台调用其它系统的dubbo接口,系统报错以上信息。

根据信息的提示,接口中的返回类型(对象)定义是:

public class outter  implements Serializable {

//内部类

public static class Inner{        

}

}

修改后:

public class outter  implements Serializable {

//内部类

public static class Inner implements Serializable {          //注意,这里要为static

}

}

参考链接:

https://blog.youkuaiyun.com/lrxb_123/article/details/73863807

 

 

Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable. To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime. During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class. A no-arg constructor must be accessible to the subclass that is serializable. The fields of serializable subclasses will be restored from the stream. When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object. Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures: private void writeObject(java.io.ObjectOutputStream out) throws IOException private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException; private void readObjectNoData() throws ObjectStreamException;
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值