Repository navigation
Support deserialization of generic types #293
Description
Activity
- changed the title
[-]Support deserialization of generic type[/-][+]Support deserialization of generic types[/+]on Jun 9, 2020 I agree with this change 100%. Can you make a PR?
I agree with this change 100%. Can you make a PR?
However,
java.lang.reflect.Typeis not easy for users to create an instance of. Jackson has aTypeReferenceto help users specify generic types easier. Maybe we should work on something like that.It involves quite a bit of work. I can PR if it agrees with you.
Makes sense. Please, go ahead.
- addedkind/enhancementNew feature or requestNew feature or request
on Jun 10, 2020 @xiazuojie Do you have plans to create a PR for this?
I have created a PR. @xiazuojie please, take a look.
It's exactly what I want. However, maybe we should also keep
<T> T deserialize(byte[] data, Class<T> clazz)
so it's not a breaking change. Also for non-generic values, It's easier to use.Sorry that I did not take time on the PR.
Also,
TypeRef<T>should implementComparable<TypeRef<T>>(just as Jackson did) as suggested here.- The serializer interface does not need two methods. It will just be confusing to users to implement two deserializers. On the other hand, every other public method in our APIs does have both variants - and that is more important for easy to use and backwards compatibility. I will add the trick with Comparable so the type is enforced. — Artur Souza…________________________________ From: xiazuojie <[email protected]> Sent: Thursday, July 9, 2020 12:22:50 AM To: dapr/java-sdk <[email protected]> Cc: Artur Souza <[email protected]>; Assign <[email protected]> Subject: Re: [dapr/java-sdk] Support deserialization of generic types (#293) Also, TypeRef<T> should implement Comparable<TypeRef<T>> (just as Jackson did) as suggested by here<https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgafter.blogspot.com%2F2006%2F12%2Fsuper-type-tokens.html&data=02%7C01%7C%7Cb6c30dcd636d49cfffbf08d823d8e35f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637298761710883337&sdata=BsYAS3NfEs%2B%2FjgxtdcoCUdsBsGlNx4OIyigfq7G1vhQ%3D&reserved=0>. — You are receiving this because you were assigned. Reply to this email directly, view it on GitHub<https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdapr%2Fjava-sdk%2Fissues%2F293%23issuecomment-655951603&data=02%7C01%7C%7Cb6c30dcd636d49cfffbf08d823d8e35f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637298761710893344&sdata=ixSTkx3Oxcuy6iYGvhPDW%2Ff%2BtJx9xiYxYtcZ6rdeL%2BA%3D&reserved=0>, or unsubscribe<https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAA77CVRI6K3WFQ3USOH5ILR2VV4VANCNFSM4NZEKTUQ&data=02%7C01%7C%7Cb6c30dcd636d49cfffbf08d823d8e35f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637298761710903345&sdata=%2Fexze8sVYSs%2Fm7HVPPQNe4iaVYWhVmzD50oCuo%2Bb5ts%3D&reserved=0>.
I've tried the Comparable<TypeRef> trick. It does not block
new TypeRef(){}from compiling. So, I did not add it. Actually, evennew TypeReference(){};from Jackson also compiles. This trick does not seem to be applicable anymore.- added a commit that references this issue
on Jan 22, 2021 - added a commit that references this issue
on Jan 22, 2021
Describe the proposal
The following deserialize API asks for a
Class<T>. It does not work with generic types.Maybe add another method with the second param as
java.lang.reflect.Type, which can accept bothjava.lang.Classandjava.lang.reflect.ParameterizedType.Jackson works with
java.lang.reflect.Typeas follows: