V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Sherman07
V2EX  ›  程序员

Fastjson 反序列化异常问题请教

  •  
  •   Sherman07 · Dec 22, 2022 · 2317 views
    This topic created in 1226 days ago, the information mentioned may be changed or developed.

    小弟在项目中使用了 Fastjson V1.8.23 ,今天发现在反序列化时产生了异常, 代码如下

        responseResult = JSON.parseObject(response.getResponseText(), new TypeReference<A<BVO>>();
        List<C> cList = responseResult.getData().getCList();
    

    其中 C 对象中含有一个 boolean 类型的属性 D ,在此处转换完成之后,C 对象的 D 属性默认成为了 false ,但是该属性未被初始化,应为 Null 值。 请大佬指点迷津,问题出在哪里

    8 replies    2022-12-24 10:11:28 +08:00
    Sherman07
        1
    Sherman07  
    OP
       Dec 22, 2022
    在尝试解决这个问题时,
    我将 D 属性改为 int 类型,仍然出现该问题,D 属性被默认赋值 0 。
    改为包装类型 Integer 时,该问题解决了,D 属性为 Null 。
    popvlovs
        2
    popvlovs  
       Dec 22, 2022
    你如果用的是 primitive type 的 boolean ,默认值就是 false ,你是想用 Boolean ?
    JxQg597
        3
    JxQg597  
       Dec 22, 2022
    boolean 是基本类型,听你的需求你应该要用的是 Boolean 。
    Java 基础知识多巩固一下....
    Sherman07
        4
    Sherman07  
    OP
       Dec 22, 2022
    @popvlovs @JxQg597 多谢大佬,反应过来了,是用了基本类型的问题...
    VensonEEE
        5
    VensonEEE  
       Dec 22, 2022
    boolean 没有 null 值 只有 true false
    honjow
        6
    honjow  
       Dec 22, 2022
    提问前还是得先把基础知识弄清楚
    JLX
        7
    JLX  
       Dec 22, 2022 via Android
    先熟悉下 Java 的基本类型和包装类型的区别
    Leon406
        8
    Leon406  
       Dec 24, 2022
    Java 基础知识多巩固一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1302 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 16:55 · PVG 00:55 · LAX 09:55 · JFK 12:55
    ♥ Do have faith in what you're doing.