fastJSON反序列化时 list为null,实体类添加构造器无用

小白第一次接触集群开发,使用谷粒商城练手,使用fastJSON反序列化时踩了一个坑。百度无果,故求大神

 

下为实体类 


@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);
            }


        });

    }

 

查看全部
qq_44919924
寻时……
2020/11/25 09:10
  • spring
  • java
  • maven
  • 点赞
  • 收藏
  • 回答
    私信

2个回复