-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
Pre-check
- I am sure that all the content I provide is in English.
Search before asking
- I had searched in the issues and found no similar issues.
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
- Dubbo Java 3.3.4
- JDK 17
- Win11
Steps to reproduce this issue
Fastjson2 Serialization Issue with Record Types in Dubbo 3.3.4
Environment:
1.Spring Boot 3.3.10
2. Dubbo Java 3.3.4
3. fastjson2 2.0.57
4. JDK 17
Problem Description
I'm encountering serialization issues when using fastjson2 as the serialization protocol between two Dubbo services (TestService and BFFService) with Java record types.
Configuration
Both services include fastjson2 dependency:
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.57</version>
</dependency>TestService (Provider)
- application.yml:
dubbo:
application:
name: shop-test-service
qos-enable: false
check-serializable: false
protocol:
port: 50556
name: tri
# serialization: hessian2
serialization: fastjson2- Service Interface:
public interface TestService {
TestResponse testDeserialize(TestRequest request);
}
@DubboService
public class TestServiceImpl implements TestService {
@Override
public TestResponse testDeserialize(TestRequest request) {
List<Student> students = request.ids().stream()
.map(id -> new Student(id, UUID.randomUUID().toString()))
.toList();
return new TestResponse(students);
}
}- Record Types
public record TestRequest(List<String> ids) implements Serializable {}
public record TestResponse(List<Student> students) implements Serializable {}
public record Student(String id, String name) implements Serializable {}BFFService (Consumer)
- application.yml
dubbo:
application:
name: bff-service-consumer
qos-enable: false
protocol:
name: tri
# serialization: hessian2
serialization: fastjson2- Service Call
@SpringBootApplication
@EnableDubbo
public class BFFApplication implements CommandLineRunner {
@DubboReference
TestService testService;
@Override
public void run(String... args) {
testService.testDeserialize(new TestRequest(List.of("123", "456")));
}
}Error Logs
TestService Error:
org.apache.dubbo.remoting.http12.exception.DecodeException: Internal Server Error
Caused by: com.alibaba.fastjson2.JSONException: array not support input TYPED_ANY -110 ["123","456"], offset 45/94BFFService Error:
java.io.IOException: org.apache.dubbo.common.serialize.SerializationException:
[Serialization Security] Serialized class org.apache.dubbo.remoting.http12.exception.DecodeException is not in allow list.
Current mode is `STRICT`, will disallow to deserialize it by default.
Please add it into security/serialize.allowlist or follow FAQ to configure it.What you expected to happen
Fastjson2 should properly support Java Record serialization/deserialization, just like it works with regular classes
The behavior should match Hessian2's current working implementation (fixed in #14820)
Anything else
Title: Fastjson2 Serialization Still Doesn't Support Record Types While Hessian2 Fix Already Implemented #14820
Related Issue: #14820 (Fix unable to deserialize Record using Hessian2)
Switching from fastjson2 to hessian2 serialization works without issues
Are you willing to submit a pull request to fix on your own?
- Yes I am willing to submit a pull request on my own!
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
Status