TriggerReactor

TriggerReactor

24.6k Downloads

Set serialization is not right

wysohn opened this issue ยท 1 comments

commented

It serialized the value into Array of Objects, then it's not trivial to deserialize the objects that are inside the Array

For example)

{
   "warps": {
      "$serkey": "java.util.Set",
      "$serval": [
         {
            "$serkey": "java.util.UUID",
            "$serval": "033ac3dd-b1b6-4930-b28b-b5cc9ff76ea8"
         },
         {
            "$serkey": "java.util.UUID",
            "$serval": "033ac3dd-b1b6-4930-b28b-b5cc9ff76ea8"
         },
         {
            "$serkey": "java.util.UUID",
            "$serval": "b0135504-b962-42a4-8d43-3a75678d4f38"
         }
      ]
   }
}

In above case, the GsonHelper will first recognize the SetSerializer when it sees "java.util.Set", yet when SetSerializer deserializes the Array, it has no ability to deserialize the UUID since Adapter and GsonHelper is not directly related.

So, like how Gson does, just store Set as Array, and load it back as ArrayList. Let the users load them into Set manually.

{
   "warps": [
      {
         "$serkey": "java.util.UUID",
         "$serval": "033ac3dd-b1b6-4930-b28b-b5cc9ff76ea8"
      },
      {
         "$serkey": "java.util.UUID",
         "$serval": "033ac3dd-b1b6-4930-b28b-b5cc9ff76ea8"
      },
      {
         "$serkey": "java.util.UUID",
         "$serval": "b0135504-b962-42a4-8d43-3a75678d4f38"
      }
   ]
}
commented