Copilot commented on code in PR #3618:
URL: https://github.com/apache/dubbo-go/pull/3618#discussion_r3746623189
##########
internal/config_test.go:
##########
@@ -349,6 +350,8 @@ func TestValidateGenericType(t *testing.T) {
if tt.wantErr {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.generic)
+ assert.Contains(t, err.Error(), "false")
+ assert.Contains(t, err.Error(),
constant.GenericSerializationProtobuf)
Review Comment:
The test currently uses `assert.Contains(err.Error(),
constant.GenericSerializationProtobuf)`, but the error string also includes
`protobuf-json`, so this assertion can pass even if the legacy `protobuf` value
is missing from the valid-values list. Tighten the assertion so it only matches
`protobuf` as a standalone entry (followed by `,` or end-of-string).
##########
filter/generic/service.go:
##########
@@ -19,40 +19,58 @@ package generic
import (
"context"
- "reflect"
)
import (
hessian "github.com/apache/dubbo-go-hessian2"
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/filter/generic/generalizer"
)
// GenericService uses for generic invoke for service call
type GenericService struct {
Invoke func(ctx context.Context, methodName string, types
[]string, args []hessian.Object) (any, error) `dubbo:"$invoke"`
referenceStr string
+ generic string
}
// NewGenericService returns a GenericService instance
func NewGenericService(referenceStr string) *GenericService {
- return &GenericService{referenceStr: referenceStr}
+ return &GenericService{referenceStr: referenceStr, generic:
constant.GenericSerializationDefault}
}
// Reference gets referenceStr from GenericService
func (s *GenericService) Reference() string {
return s.referenceStr
}
+// SetGenericType sets the generic mode used by InvokeWithType to realize
typed results.
+func (s *GenericService) SetGenericType(generic string) error {
+ if isGenericDisabled(generic) {
+ s.generic = generic
+ return nil
+ }
+ if _, err := getGeneralizer(generic); err != nil {
+ return err
+ }
+ s.generic = generic
+ return nil
+}
+
+// GenericType returns the generic mode used by InvokeWithType.
+func (s *GenericService) GenericType() string {
+ return s.generic
+}
+
// InvokeWithType invokes the remote method and deserializes the result into
the reply struct.
// The reply parameter must be a non-nil pointer to the target type.
//
-// Note: This method uses MapGeneralizer for deserialization, which means it
only supports
-// the default map-based generic serialization (generic=true). If you are
using other
-// serialization types like Gson or Protobuf-JSON, use the Invoke method
directly and
-// handle deserialization manually.
+// InvokeWithType uses the service generic mode to realize the result.
Supported modes are
+// true, gson, bean, protobuf-json, and the legacy protobuf alias.
generic=false disables
+// generic result realization and returns an explicit error.
Review Comment:
The doc comment calls `protobuf` a “legacy protobuf alias”, but in
`getGeneralizer` it maps to the Map/Hessian generalizer (different semantics
from `protobuf-json`). Wording this as “legacy protobuf mode (Map/Hessian
semantics)” avoids implying it is an alias of `protobuf-json`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]