FastJson com.alibaba.fastjson.JSONException: parseInt error, field : id问题解决
fastjson
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
项目地址:https://gitcode.com/gh_mirrors/fastj/fastjson
免费下载资源
·
问题描述:
com.alibaba.fastjson.JSONException: parseInt error, field : id
问题分析:
1、使用JSON.parseArray()进行实体类类型转换时,UserEntity的id属性类型为Long,而UserDto的id属性类型为Integer,导致UserEntity转换为UserDto时,Long类型转换不了Integer类型,导致报错。
List<UserEntity> userEntityList = new ArrayList<>(Arrays.asList(new UserEntity(1432957941805654017L)));
List<UserDto> userDtoList = JSON.parseArray(JSON.toJSONString(userEntityList, SerializerFeature.WriteMapNullValue), UserDto.class);
package com.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserEntity {
private Long id;
}
package com.entity;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class UserDto {
private Integer id;
}
解决办法:
两个实体类对应的属性类型一致即可。
GitHub 加速计划 / fastj / fastjson
3
1
下载
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
最近提交(Master分支:4 个月前 )
c942c834 - 1 年前
5bc4709b - 1 年前
更多推荐
已为社区贡献20条内容
所有评论(0)