apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.55k stars 26.44k forks source link

[Feature][3.3] Enhance JsonCompatibilityUtil to support triple protocol #13963

Open AlbumenJ opened 8 months ago

AlbumenJ commented 8 months ago

Pre-check

Search before asking

Apache Dubbo Component

Java SDK (apache/dubbo)

Descriptions

Enhance JsonCompatibilityUtil to support triple protocol none-annotation mode (application/json)

Related issues

No response

Are you willing to submit a pull request to fix on your own?

Code of Conduct

hengyoush commented 8 months ago

I can try solve it, please assign to me

CrazyHZM commented 8 months ago

@hengyoush Go ahead

hengyoush commented 8 months ago

Before I start, I have some questions about this issue:

AlbumenJ commented 8 months ago

Before I start, I have some questions about this issue:

  • Check all the types that Dubbo can support: I guess the current JsonCompatibilityUtil already has the functionality to check the compatibility of classes. Is it the same usage as JsonCompatibilityUtil in RestProtocol, and should we also use JsonCompatibilityUtil to do the same thing in TripleProtocol?
// this is the JsonCompatibilityUtil in RestProtocol
private void checkJsonCompatibility(Class<?> clazz, String jsonCheckLevel) throws RpcException {

        if (jsonCheckLevel == null || JSON_CHECK_LEVEL_WARN.equals(jsonCheckLevel)) {
        //....
        List<String> unsupportedMethods = JsonCompatibilityUtil.getUnsupportedMethods(clazz);
        } else if (JSON_CHECK_LEVEL_STRICT.equals(jsonCheckLevel)) {
        // ...
        }
    }
  • Generate the demo json struct: Does JsonCompatibilityUtil need to generate corresponding sample JSON structures based on interface parameters during the validation process?
hengyoush commented 8 months ago

Before I start, I have some questions about this issue:

  • Check all the types that Dubbo can support: I guess the current JsonCompatibilityUtil already has the functionality to check the compatibility of classes. Is it the same usage as JsonCompatibilityUtil in RestProtocol, and should we also use JsonCompatibilityUtil to do the same thing in TripleProtocol?
// this is the JsonCompatibilityUtil in RestProtocol
private void checkJsonCompatibility(Class<?> clazz, String jsonCheckLevel) throws RpcException {

        if (jsonCheckLevel == null || JSON_CHECK_LEVEL_WARN.equals(jsonCheckLevel)) {
        //....
        List<String> unsupportedMethods = JsonCompatibilityUtil.getUnsupportedMethods(clazz);
        } else if (JSON_CHECK_LEVEL_STRICT.equals(jsonCheckLevel)) {
        // ...
        }
    }
  • Generate the demo json struct: Does JsonCompatibilityUtil need to generate corresponding sample JSON structures based on interface parameters during the validation process?
  • In TripleProtocol
  • No. This is a explict feature. @oxsean Do you have any ideas?

I have completed the 1. and 3, but I am still confused about the second(Generate the demo json struct). Assuming we have a class like:

 public class DemoClass {
      private String str;
      private Set<String> set;
  }

and get a String through String demoStruct = JsonCompatibilityUtil.generateDemoJsonStruct(Class clazz):

{
    "str": "foobar",
    "set": ["v1", "v2"]
}

Is my understanding correct?

oxsean commented 6 months ago

@AlbumenJ Sorry for later to noticed this Should the focus be on leveraging JsonCompatibilityUtil in TripleProtocol to check compatibility? This should already be available. Generating the demo json structure may not be needed currently, but it could be useful for future support of OpenAPI.