fastjson 在web请求的时候报错,"java.lang.Integer cannot be cast to java.lang.Long
web请求,请求参数
{name: "zhansan", description: "飒飒大讲述了克里斯",…}
description:"飒飒大讲述了克里斯"
functions:[{id: 1}, {id: 41}, {id: 47}, {id: 49}, {id: 50}]
name:"zhansan"
后台接收参数方法:
@RequestMapping("/saveOrUpdate")
public @ResponseBody ResponseEntity<String> saveOrUpdate(@RequestBody Role role) {
roleService.saveOrUpdate(role);
return ResponseEntity.ok("success");
}
返回结果:
{
"timestamp":1493972641002,
"status":500,
"error":"Internal Server Error",
"exception":"com.alibaba.fastjson.JSONException",
"message":"java.lang.Integer cannot be cast to java.lang.Long",
"path":"/role/saveOrUpdate.htm"
}
Role 对象中存在一个function对象的集合,function对象中id 的属性类型是Long类型,结果报错java.lang.Integer cannot be cast to java.lang.Long,这个问题是怎么导致的,而且这个问题是有时候会出现,有时候不会出现,怎么解决?
package com.control.back.halo.manage.entity;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import com.control.back.halo.basic.entity.BaseEntity;
@Entity
@Table(name = "sys_role")
public class Role extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 820694530776191567L;
// fields
private java.lang.String name;
private java.lang.String description;
// collections
@ManyToMany(mappedBy = "roles")
private java.util.Set<Admin> admins;
@ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@JoinTable(name = "sys_role_function", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "function_id") })
private java.util.Set<Function> functions;
/**
* Return the value associated with the column: NAME
*/
public java.lang.String getName() {
return name;
}
/**
* Set the value related to the column: NAME
*
* @param name
* the NAME value
*/
public void setName(java.lang.String name) {
this.name = name;
}
/**
* Return the value associated with the column: DESCRIPTION
*/
public java.lang.String getDescription() {
return description;
}
/**
* Set the value related to the column: DESCRIPTION
*
* @param description
* the DESCRIPTION value
*/
public void setDescription(java.lang.String description) {
this.description = description;
}
/**
* Return the value associated with the column: admins
*/
public java.util.Set<Admin> getAdmins() {
return admins;
}
/**
* Set the value related to the column: admins
*
* @param admins
* the admins value
*/
public void setAdmins(java.util.Set<Admin> admins) {
this.admins = admins;
}
/**
* Return the value associated with the column: functions
*/
public java.util.Set<Function> getFunctions() {
return functions;
}
/**
* Set the value related to the column: functions
*
* @param functions
* the functions value
*/
public void setFunctions(java.util.Set<Function> functions) {
this.functions = functions;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
恩,谢谢指点
回复
@hiyou : 不用谢, 毕竟没有帮到你
看不出什么异常Function和Admin都看不到, 把代码剥离出来, 直接用fastjson把你那段json转换成Role测试下
你能不能仔细看看
回复
@hiyou : Role实体类的代码贴出来
回复
@夜丶魂 : 你看吧
建议把实体类贴出来, 不然数据类型都看不到, 异常描述的很清楚, 类型转换错误
我说的不是时间戳类型转换
这个timestamp?
引用来自“夜丶魂”的评论
Integer放不下时间戳, 改成Long即可
Integer放不下时间戳, 改成Long即可