fix: preserve generic parameter types during deserialization to fix List<Byte> → List<Integer> [3.2]#16199
Closed
uuuyuqi wants to merge 5 commits intoapache:3.2from
Closed
fix: preserve generic parameter types during deserialization to fix List<Byte> → List<Integer> [3.2]#16199uuuyuqi wants to merge 5 commits intoapache:3.2from
uuuyuqi wants to merge 5 commits intoapache:3.2from
Conversation
When RPC methods have parameters like List<Byte>, Map<String, Byte>, or List<Short>, the provider-side deserialization incorrectly produces List<Integer> / Map<String, Integer> because the generic type info is discarded. This fix addresses the issue across three layers: 1. Model layer: add getGenericParameterTypes() to MethodDescriptor (default method for backward compat) and implement it in ReflectionMethodDescriptor to expose Type[] for parameters. 2. Protocol layer: update DecodeableRpcInvocation.drawArgs() (Dubbo protocol) and ReflectionPackableMethod.WrapRequestUnpack (Triple protocol) to pass generic Type to the serialization framework. 3. Serialization layer: fix Hessian2ObjectInput.readObject(Class, Type) to post-convert collection/map elements to the correct narrow number type (Byte, Short, Float). No wire protocol changes needed. Change-Id: Ifefdd0cd9719de380ef5b3b6076e51123781cbb8 Co-developed-by: Cursor <noreply@cursor.com>
…ype) Add NarrowNumberPojo with byte/short/float fields and List<Byte>/ Map<String, Byte> fields to verify that POJO deserialization via readObject(Class, Type) is not affected by the generic type fix. Change-Id: I07751b608827b03ad4ac7b02704b522751ecbea8 Co-developed-by: Cursor <noreply@cursor.com>
…ype handling Use hessian2's built-in expectedTypes support instead of post-processing conversion, as suggested in review. Change-Id: I1cbb65a684f2f03aa7219826f1fa866b6d7d79cc Co-developed-by: Cursor <noreply@cursor.com>
Hessian2Input.readObject(Class, Class...) expectedTypes mechanism only works correctly for simple types. For complex POJO types like User, passing the class as expectedType causes CollectionDeserializer to use a wrong deserializer, leading to HessianProtocolException. Change-Id: If909026ae4f9633155ffd5bd5c7b318aa77f492b Co-developed-by: Cursor <noreply@cursor.com>
…pectedTypes filtering Align the type filtering logic with hessian-lite's FieldDeserializer2Factory, using isPrimitive() to cover all primitive wrapper types instead of only narrow number types (Byte/Short/Float). Change-Id: If4dd8f961ec3b3a8e4f2881a866f527777e7a47d Co-developed-by: Cursor <noreply@cursor.com>
Contributor
|
3.2 might not be maintained anymore. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16197
Summary
Backport of #16198 to the 3.2 branch.
When RPC methods have parameters like
List<Byte>,Map<String, Byte>, orList<Short>, the provider-side deserialization incorrectly producesList<Integer>/Map<String, Integer>because the generic type information is discarded during deserialization.This PR fixes the issue across three layers:
getGenericParameterTypes()toMethodDescriptor(default method for backward compat) and implement it inReflectionMethodDescriptorto exposeType[]for method parameters.DecodeableRpcInvocation.drawArgs()(Dubbo protocol) andReflectionPackableMethod.WrapRequestUnpack(Triple protocol) to pass genericTypeto the serialization framework when available.Hessian2ObjectInput.readObject(Class, Type)to post-convert collection/map elements to the correct narrow number type (Byte,Short,Float).No wire protocol changes needed. The fix leverages existing local reflection information on the provider side.
Changes
MethodDescriptor.javadefault getGenericParameterTypes()ReflectionMethodDescriptor.javaDecodeableRpcInvocation.javaTypeindrawArgs()ReflectionPackableMethod.javaTypeinWrapRequestUnpackMultipleSerialization.javadeserialize(url, type, clz, genericType, is)overloadDefaultMultipleSerialization.javaHessian2ObjectInput.javaTest plan
ReflectionMethodDescriptor.getGenericParameterTypes()Hessian2ObjectInput.readObject(Class, Type)withList<Byte>,List<Short>,List<Float>,Map<String, Byte>Made with Cursor