Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dubbo3处理boolean属性(默认值为true)时,服务端设置为false,但客户端拿到的是ture #12833

Closed
1 task done
liyesa opened this issue Aug 3, 2023 · 19 comments
Labels
type/bug Bugs to being fixed

Comments

@liyesa
Copy link

liyesa commented Aug 3, 2023

  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 3.2.4
  • Operating System version: x86_64 Linux
  • Java version: openJDK 17

Steps to reproduce this issue

  1. service result类,包含4个boolean属性,两个默认值为true
public class Foo implements Serializable {
    boolean success = true;
    boolean success1 = true;    
    boolean success2;
    boolean success3;
    String message;
    
    // getter,setter
    ...

  1. DubboService将4个boolean属性全部设置为false,并返回
@DubboService
public class TestServiceImpl implements TestService {
    @Override
    public Foo foo() {
        Foo c = new Foo();
        c.setSuccess(false);
        c.setSuccess1(false);
        c.setSuccess2(false);
        c.setSuccess3(false);
        c.setMessage("success");
        return c;
    }
}
  1. bug: 返回结果,默认值为true的属性,接口返回值为true,而不是service设置的false
 @DubboReference
    TestService testService;

    @RequestMapping("/test")
    public Foo test() {
        return testService.foo();
    }
// result
{"success":true,"success1":true,"success2":false,"success3":false,"message":"success"}

Pls. provide [GitHub address] to reproduce this issue.
sample code:
https://github.com/liyesa/dubbo-bug

Expected Behavior

boolean值能正确返回

Actual Behavior

有初始值=true的boolean属性,client拿到的永远是false;
补充:
在doubbo admin执行,返回结果正常
在telnet执行,返回结果正常
设置preferSerialization为 hessian2,返回结果正确

If there is an exception, please attach the exception trace:

NONE error log

@liyesa liyesa added the type/bug Bugs to being fixed label Aug 3, 2023
@C20171008S
Copy link

试了一下确实有问题

@C20171008S
Copy link

JSON序列化的问题

@C20171008S
Copy link

C20171008S commented Aug 3, 2023

我已经在fastjson2仓库提了bug
alibaba/fastjson2#1710

@liyesa
Copy link
Author

liyesa commented Aug 3, 2023

我已经在fastjson2仓库提了bug alibaba/fastjson2#1710
@C20171008S

那是JSONWriter.Feature.NotWriteDefaultValue的问题了? bugfix前建议怎么处理,preferSerialization改用hessian2吗?

@C20171008S
Copy link

我已经在fastjson2仓库提了bug alibaba/fastjson2#1710
@C20171008S

那是JSONWriter.Feature.NotWriteDefaultValue的问题了? bugfix前建议怎么处理,preferSerialization改用hessian2吗?

只能等待修复

@q1angch0u
Copy link

尝试了下,用包装类好像可以解决~

@q1angch0u
Copy link

在Java中,boolean的默认值为false,fastjson的NotWriteDefaultValue中的"DefaultValue"意义为:只要boolean值为false,就认为其为默认值,不进行序列化;包装类的"DefaultValue"为null,所以就不会导致这个问题了。

@C20171008S
Copy link

在Java中,boolean的默认值为false,fastjson的NotWriteDefaultValue中的"DefaultValue"意义为:只要boolean值为false,就认为其为默认值,不进行序列化;包装类的"DefaultValue"为null,所以就不会导致这个问题了。

包装类或者不设置默认值都能解决,但这个本身算一个巨大的问题。序列化前后不一样,要么dubbo去改要么fastjson那边去改

@AlbumenJ
Copy link
Member

AlbumenJ commented Aug 9, 2023

这个参数是 fastjson2 侧为了减低序列化包大小使用的,具体怎么修复还需要 @wenshao 看一下

@dujie-js
Copy link

感觉fastjson2现在还不太稳定呀

@C20171008S
Copy link

C20171008S commented Aug 11, 2023

感觉fastjson2现在还不太稳定呀

怎么能说是不太稳定呢,那是相当的不稳定。

@wenshao
Copy link
Contributor

wenshao commented Aug 13, 2023

序列化的配置去掉这个:

JSONWriter.Feature.NotWriteDefaultValue

@wenshao
Copy link
Contributor

wenshao commented Aug 13, 2023

感觉fastjson2现在还不太稳定呀

怎么能说是不太稳定呢,那是相当的不稳定。

这个是序列化时配置了JSONWriter.Feature.NotWriteDefaultValue,序列化时boolean的false值就不输出了,而反序列化时没有值,用到了类中的缺省值。

@C20171008S
Copy link

感觉fastjson2现在还不太稳定呀

怎么能说是不太稳定呢,那是相当的不稳定。

这个是序列化时配置了JSONWriter.Feature.NotWriteDefaultValue,序列化时boolean的false值就不输出了,而反序列化时没有值,用到了类中的缺省值。

那现在这种对不上的不算问题? @AlbumenJ 是不是Dubbo这边要去掉这个配置?

@wenshao
Copy link
Contributor

wenshao commented Aug 13, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.39-SNAPSHOT/
fastjson2已修复该问题,请帮忙用2.0.39-SNAPSHOT版本验证,2.0.39版本预计在8月27日前发布

@C20171008S
Copy link

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.39-SNAPSHOT/ fastjson2已修复该问题,请帮忙用2.0.39-SNAPSHOT版本验证,2.0.39版本预计在8月27日前发布

经过测试,上述问题已经解决。

@wenshao
Copy link
Contributor

wenshao commented Aug 15, 2023

https://github.com/alibaba/fastjson2/releases/tag/2.0.39
请更新fastjson到2.0.39版本

@liyesa
Copy link
Author

liyesa commented Aug 17, 2023

这个参数是 fastjson2 侧为了减低序列化包大小使用的,具体怎么修复还需要 @wenshao 看一下

请问dubbo计划什么时间发布对应fastjson 2.0.39的版本? @AlbumenJ

@AlbumenJ
Copy link
Member

这个参数是 fastjson2 侧为了减低序列化包大小使用的,具体怎么修复还需要 @wenshao 看一下

请问dubbo计划什么时间发布对应fastjson 2.0.39的版本? @AlbumenJ

预计下周或者后周发布

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

No branches or pull requests

7 participants