tugberkugurlu / AspNet.Identity.RavenDB

Fully asynchronous, new and sweet ASP.NET Identity implementation for RavenDB
MIT License
42 stars 28 forks source link

Add JsonConstructor attribute to RavenUserClaim constructor #25

Closed marisks closed 10 years ago

marisks commented 10 years ago

Attribute should be added for

[JsonConstructor]
public RavenUserClaim(string claimType, string claimValue)

Here is the Exception when searching for user:

Unable to find a constructor to use for type AspNet.Identity.RavenDB.Entities.RavenUserClaim. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'Claims[0].ClaimType'.

Also I need in my project importing of test data on application startup. I am reading JSON text file, deserializing to proper object and store it into RavenDB and can't deserialize it with same exception. Here is how I am deserializing:

private static void Insert<T>(IDocumentSession session, string path)
{
    var folder = new DirectoryInfo(path);
    var files = folder.EnumerateFiles("*.json");
    foreach (var fileInfo in files)
    {
        var c = File.ReadAllText(fileInfo.FullName);
        var obj = JsonConvert.DeserializeObject<T>(c);

        session.Store(obj);
    }
}
tugberkugurlu commented 10 years ago

Thx! try out the new release: https://www.nuget.org/packages/AspNet.Identity.RavenDB/2.0.0-pre-04

It should solve your first problem. Interesting that I didn't come accross that error in my unit tests.

For your second problem, I'm not sure it will work out or not as JsonConstructor in RavenDB.Client is from the embedded JSON.NET. to work around the issue, you can create your own RavenUserClaim by making it derived from RavenUserClaim and put the necessary attributes on it.

marisks commented 10 years ago

Thanks! Search now works.