Cannot serialize; nested exception is nested exception is java.io.NotSerializableException:

在将实体类以Object类型存储到redis中报了未序列化异常。。

Cannot serialize; nested exception is
org.springframework.core.serializer.support.SerializationFailedException:Failed
to serialize object using DefaultSerializer; nested exception is
java.io.NotSerializableException: xxx
@Data
@TableName("t_charger_pile")
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class ChargerEntity implements Serializable {
	private static final long serialVersionUID = 42L;
	...
}

发现其实这个实体类是有实现序列化的。。后来想想,,错误提示一般不会出错。。那就还有一种可能。。它内部的实体类可能未实现序列化。仔细检查代码:

@Data
@TableName("t_charger_pile")
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class ChargerEntity implements Serializable {
	private static final long serialVersionUID = 42L;
	...
	
	@TableField(exist = false)
	@NotEmpty(message = "枪信息不能为空")
	private List list;
}

检查 ChargerGunEntity 实体类:


@Data
@TableName("t_charger_pile_gun")
public class ChargerGunEntity  {
	private Long id;
	....
}

果然发现未实现序列化,修改代码如下:

@Data
@TableName("t_charger_pile_gun")
public class ChargerGunEntity implements Serializable {
	private static final long serialVersionUID = 42L;
	...
}

重新启动项目,重新执行,,问题解决!
总结:redis在存储对象时,对象及对象中的所有子对象必须都实现序列化

你可能感兴趣的:(redis,springCloud,redis,java,序列化,NotSerializable,异常)