provider泛型类型为Float时返回Double类型
- [X] I have searched the issues of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 3.0.7
- Operating System version: Linux Ubuntu-20.04
- Java version: 1.8
Steps to reproduce this issue
- provider返回泛型为Float
- consumer以Float接收返回参数
Demo地址: https://github.com/natsumm/dubbo-generic-float-issue
Expected Behavior
返回Float类型参数
Actual Behavior
返回了Double类型参数,并抛出java.lang.ClassCastException
Detail
- provider端代码
@DubboService
public class DemoServiceImpl implements DemoService {
@Override
public String sayHello(String name) {
return "Hello " + name;
}
//此处定义为Float类型
@Override
public List<Float> getFloats() {
List<Float> floats = new ArrayList<>();
floats.add(35.3F);
floats.add(45.1F);
return floats;
}
}
- consumer端代码
@SpringBootApplication
@Service
@EnableDubbo
public class ConsumerApplication {
@DubboReference
private DemoService demoService;
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(ConsumerApplication.class, args);
ConsumerApplication application = context.getBean(ConsumerApplication.class);
String result = application.doSayHello("world");
System.out.println("result: " + result);
//此处返回了Double类型
List<Float> floats = application.getFloats();
System.out.println("floats = " + floats);
Float aFloat = floats.get(0);
}
public String doSayHello(String name) {
return demoService.sayHello(name);
}
public List<Float> getFloats() {
return demoService.getFloats();
}
}
- 预期返回Float类型实际Double
经验证,dubbo 3.0.0~3.1.5均存在此问题
Yes, the problem is caused by serialization of float by hessian.
However, when I used other serialization protocols(like kryo and sft), it still returned Double type except nativejava.
However, when I used other serialization protocols(like
kryoandsft), it still returned Double type exceptnativejava.
Thank you for your feedback. Let's wait for the fix.
Thank you for your feedback. Let's wait for the fix.
Ok, thank you for the reply.
I try to use fastjson2, kryo and sft that it return float. I think the problem is hessian serialization. org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcResult#handleValue http://hessian.caucho.com/doc/hessian-serialization.html
dubbo version: 3.1.5
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-serialization-kryo</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-serialization-fst</artifactId>
<version>1.0.0</version>
</dependency>
我目前是这么处理的 dubbo.version = 3.1.5
1 application.yml
dubbo:
protocols:
dubbo:
name: dubbo
serialization: fst
2 pom.xml
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-fst</artifactId>
</dependency>
我目前是这么处理的 dubbo.version = 3.1.5
1 application.yml
dubbo: protocols: dubbo: name: dubbo serialization: fst2 pom.xml
<dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-serialization-fst</artifactId> </dependency>
使用fst插件的版本为 2.7.22