寻时…… 2020-11-25 09:23 采纳率: 50%
浏览 563
已采纳

fastJSON反序列化时list为null

小白第一次接触集群开发,使用谷粒商城作为练手项目,做秒杀服务时,使用fastJSON中 

JSON.parseObject(jsonString,tTypeReference);

方法,打印出来的list是null,百度无果,故求大神。

下面贴出代码

实体类

@AllArgsConstructor
@NoArgsConstructor
@Data
public class SeckillSesssionsWithSkus implements Serializable {

    private Long id;
    /**
     * 场次名称
     */
    private String name;
    /**
     * 每日开始时间
     */
    private Date startTime;
    /**
     * 每日结束时间
     */
    private Date endTime;

    private Integer status;

    private Date createTime;

    private List<SeckillSkuVo> relationSkus;





}

工具类

public <T> T  getData(TypeReference<T> tTypeReference){
		Object data = get("data");
		System.err.println("data---->>>"+data.toString());
		String jsonString = JSON.toJSONString(data);
		System.err.println("jsonString----->>>"+jsonString);
		T t = JSON.parseObject(jsonString,tTypeReference);
		System.err.println("t----->>>>"+t.toString());
		return t;
	}

工具类打印出来的数据

data---->>>[{id=3, name=test, startTime=2020-11-24T16:00:00.000+00:00, endTime=2020-11-26T16:00:00.000+00:00, status=1, createTime=2020-11-24T02:48:16.000+00:00, relationsku=[{id=3, promotionId=null, promotionSessionId=3, skuId=1, seckillPrice=1, seckillCount=4, seckillLimit=2, seckillSort=99}, {id=4, promotionId=null, promotionSessionId=3, skuId=1, seckillPrice=1, seckillCount=1, seckillLimit=1, seckillSort=99}, {id=5, promotionId=null, promotionSessionId=3, skuId=5, seckillPrice=0, seckillCount=1, seckillLimit=1, seckillSort=55}]}]
jsonString----->>>[{"id":3,"name":"test","startTime":"2020-11-24T16:00:00.000+00:00","endTime":"2020-11-26T16:00:00.000+00:00","status":1,"createTime":"2020-11-24T02:48:16.000+00:00","relationsku":[{"id":3,"promotionSessionId":3,"skuId":1,"seckillPrice":1,"seckillCount":4,"seckillLimit":2,"seckillSort":99},{"id":4,"promotionSessionId":3,"skuId":1,"seckillPrice":1,"seckillCount":1,"seckillLimit":1,"seckillSort":99},{"id":5,"promotionSessionId":3,"skuId":5,"seckillPrice":0,"seckillCount":1,"seckillLimit":1,"seckillSort":55}]}]
t----->>>>[SeckillSesssionsWithSkus(id=3, name=test, startTime=Wed Nov 25 00:00:00 CST 2020, endTime=Fri Nov 27 00:00:00 CST 2020, status=1, createTime=Tue Nov 24 10:48:16 CST 2020, relationSkus=null)]
sessionData---->>>>[SeckillSesssionsWithSkus(id=3, name=test, startTime=Wed Nov 25 00:00:00 CST 2020, endTime=Fri Nov 27 00:00:00 CST 2020, status=1, createTime=Tue Nov 24 10:48:16 CST 2020, relationSkus=null)]

 

业务层  调用

sesssion.getRelationSkus()

为null

  private void  saveSessionInfos(List<SeckillSesssionsWithSkus> sesssions){
        sesssions.stream().forEach(sesssion->{
            Long startTime = sesssion.getStartTime().getTime();
            Long endTime = sesssion.getEndTime().getTime();

            String key =SESSIONS_CACHE_PREFIX + startTime+"_"+endTime;
            Boolean hasKey = redisTemplate.hasKey(key);
            if (!hasKey){

                List<String> collect = sesssion.getRelationSkus()
                        .stream()
                        .map(
                                item -> item.getPromotionSessionId()+"_"+item.getSkuId().toString()
                        )
                        .collect(Collectors.toList());
                //缓存活动信息
                redisTemplate.opsForList().leftPushAll(key,collect);
            }


        });

    }

 

  • 写回答

2条回答 默认 最新

  • qq_25376897 2020-11-25 11:37
    关注

    你的data里面用的是relationsku,SeckillSesssionsWithSkus里面的是relationSkus,一个小写s,一个大写S

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥15 寻找能匹配的液晶显示屏。