JsonApiNet icon indicating copy to clipboard operation
JsonApiNet copied to clipboard

ResourceFromDocument doesn't work when types in Json are not plural

Open phil-E opened this issue 9 years ago • 4 comments

Hi, I'm using JsonApiNet to deserialize a compound Json document, however the data types in the Json are singular rather than plural (e.g. "vendor" rather than "vendors"). This causes an error when calling JsonApi.ResourceFromDocument. Am I missing something? If I change the data types to plurals (i.e. vendors, addresses and contacts) it works fine. I do not have control over the generation of the Json.

I have attached the Json that does not work.

Many thanks,

Phil

VendorJson - with singular types.txt

phil-E avatar May 13 '16 08:05 phil-E

I have found the issue in ReflectingTypeResolver.cs. Changing: private static string Classify(string typeName) { return typeName.Underscore().Singularize().Pascalize(); } to: private static string Classify(string typeName) { return typeName.Underscore().Singularize(false).Pascalize(); } The bool parameter "inputIsKnownToBePlural" defaults to true, which causes an error if it's not plural.

phil-E avatar May 13 '16 12:05 phil-E

Nice find. Want to submit a PR?

On May 13, 2016, at 05:57, phil-E [email protected] wrote:

I have found the issue in ReflectingTypeResolver.cs. Changing: private static string Classify(string typeName) { return typeName.Underscore().Singularize().Pascalize(); } to: private static string Classify(string typeName) { return typeName.Underscore().Singularize(false).Pascalize(); } The bool parameter "inputIsKnownToBePlural" defaults to true, which causes an error if it's not plural.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

l8nite avatar May 13 '16 13:05 l8nite

Has this been fixed yet?

lordplagus02 avatar Sep 18 '16 23:09 lordplagus02

It hasn't. I'll gladly accept a pull request otherwise I'll see if I can squeeze some time in for this this week

Edit: Typos, thanks Siri.

On Sep 18, 2016, at 16:26, lordplagus02 [email protected] wrote:

Has this been fixed yet?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

l8nite avatar Sep 18 '16 23:09 l8nite