sofastack / sofa-rpc-node

SOFARPC Node is a high-performance, high-extensibility, production-level Nodejs RPC framework.
MIT License
612 stars 64 forks source link

node通过hessian调用java 参数org.bson.Document序列化异常 #20

Closed liuyang-zhituanbox closed 5 years ago

liuyang-zhituanbox commented 5 years ago

sofa-test-1.zip

gxcsoccer commented 5 years ago

org.bson.Document 这个类型比较特殊,它继承了 Map 接口,所以它的属性不是固定(一般正常的 class 结构是确定的)

我们 hessian 实现对于这种自定义的 Map 暂时无法识别,所以把他当成一个普通的类型处理,导致问题

gxcsoccer commented 5 years ago

我们的解决方案是,你在写这个参数的时候,需要显示的指定它是一个 map (通过 isMap => true)

下面是一个例子:

const document = {
  $class: 'org.bson.Document',
  $: {
    _id: {
      $class: 'org.bson.Document',
      $: {
        $in: [
          '5bd6a201c816e527d97cb1ad',
        ],
      },
      isMap: true, // mark it as a Map
    },
  },
  isMap: true, // mark it as a Map
};