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

[BUG]Tuple2<A,B>被序列化为List<Object> #554

Closed
pusabless opened this issue Jul 13, 2022 · 6 comments
Closed

[BUG]Tuple2<A,B>被序列化为List<Object> #554

pusabless opened this issue Jul 13, 2022 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@pusabless
Copy link

问题描述

简要描述您碰到的问题。

环境信息

  • OS信息: macos
  • JDK信息:Openjdk 1.8.0_312
  • 版本信息:Fastjson2 2.0.8

重现步骤

  1. Tuples.of(new A(),new B())构造Tuple2<A,B> data对象
  2. 使用com.alibaba.fastjson2.JSON.toJSONString(data)
  3. 输出结果为[{},{}]

期待的正确结果

期望输出{"t1":{},"t2":{}}

附加信息

com.alibaba.fastjson和gson的序列化结果都是 {"t1":{},"t2":{}}

@pusabless pusabless added the bug Something isn't working label Jul 13, 2022
@wsxe9988
Copy link
Contributor

麻烦提供下完整的case,以供复现

@pusabless
Copy link
Author

pusabless commented Jul 13, 2022

  
  import com.google.gson.Gson;
  import reactor.util.function.Tuple2;
  import reactor.util.function.Tuples;

  public class Test {
      
        static class A {
                private String a;
        
                public A(String a) {
                    this.a = a;
                }
        
                public String getA() {
                    return a;
                }
        
                public void setA(String a) {
                    this.a = a;
                }
            }
        
            static class B {
                private String b;
        
                public B(String b) {
                    this.b = b;
                }
        
                public String getB() {
                    return b;
                }
        
                public void setB(String b) {
                    this.b = b;
                }
            }
  
          public static void main(String[] args) {
              Tuple2<A, B> data = Tuples.of(new A("a"), new B("b"));
              Gson gson = new Gson();
              System.out.println("fastjson2:" + com.alibaba.fastjson2.JSON.toJSON(data));
              System.out.println("fastjson:" + com.alibaba.fastjson.JSON.toJSON(data));
              System.out.println("gson:" + gson.toJson(data));
          }
  }

输出结果:
image

@dujie-js
Copy link

补充引用jar包

io.projectreactor
reactor-core
3.4.21

@SuperEdison
Copy link

我感觉ObjectWriterImplIterable默认使用的就是[]而ObjectWriterImplCollection继承了他,如果是Iterable的不一定一定是Collection但是Collection一定是可Iterable的,所以去掉
image
这个又正常了 而看实现Collection默认使用的是Iterable的write方法,不同的是JSONB,JSONB不是很了解所以不知道解决。

@wenshao wenshao added this to the 2.0.10 milestone Jul 13, 2022
@wenshao
Copy link
Member

wenshao commented Jul 13, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.10-SNAPSHOT/
问题已修复,请用2.0.10-SNAPSHOT版本验证,2.0.10版本预计在2月24日发布

@wenshao
Copy link
Member

wenshao commented Jul 23, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.10
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants