Skip to content

Cannot deserialize HashSet<> #129

@jhughes2112

Description

@jhughes2112

I have a class that contains a HashSet in it. The output looks perfect and contains the string entries as expected. Deserializing that file back into a class fails with an invalid cast, approximately here in JSON.cs (776):

                                    if (pi.IsGenericType && pi.IsValueType == false && v is List<object>)
                                        oset = CreateGenericList((List<object>)v, pi.pt, pi.bt, globaltypes);

No specific type seems to be stored in the $types array. Here's an example, where bseos is a HashSet:

{
   "$types" : {
      "MockServer.SerializedAccount, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" : "1"
   },
   "$type" : "1",
   "username" : "jhughes2112",
   "bseos" : [
      "bee79025-5908-4235-9095-c0da046fb461",
      "377c212a-60dc-4b52-8e91-32fa1a8bb4c2"
   ]
}

I can convert this to a List for serialization purposes in my case, but it would be worth supporting the correct generic collection.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions