Skip to content

Add explicit conversion from underlying type to LikeType #2

Description

@mattklein999

I'm running into an issue where Json.net won't deseralize this:

class MyKey : LikeType<string> { ... }
class MyVal : LikeType<int> { ... }

class MyCollection : LikeType<IReadOnlyDictionary<MyKey,MyVal>> { ... }

void ShowError(IJsonSerializer j, MyCollection val){
    var data = j.Seralize(val);
    var result = j.Deseralize(data, typeof(MyCollection)); //Blows up
}

I think the deserialize method is trying to send an IReadOnlyDictionay<string,MyVal> into the MyCollection constructor and throws this exception

Could not convert string 'value4eea4a6f-b2fa-428e-b245-9725e7f75798' to dictionary key type 'MyKey'. Create a TypeConverter to convert from the string to the key type object.

I suspect that if we have an explicit conversion then JSON.net may know how to make this work.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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