IsaacSchemm / DeviantArtFs

F# library for the DeviantArt and Sta.sh API
Other
1 stars 0 forks source link

Inconsistencies in deviation object format result in deserialization error #9

Open AlexCSDev opened 2 months ago

AlexCSDev commented 2 months ago

Hello, while using DeviantArtFs.Api.Browse.PageNewestAsync method I have noticed that there is an inconsisency in returned deviation objects which results in the following error:

FSharp.Json.JsonDeserializationError: JSON Path: results[117].tier.stats. Failed to parse record from JSON that is not object.
   at FSharp.Json.Core.failDeserialization[a](JsonPath path, String message)
   at FSharp.Json.Core.deserializeRecord@463(JsonConfig config, JsonPath path, Type t, JsonValue jvalue)
   at FSharp.Json.Core.deserializeNonOption@322(JsonConfig config, JsonPath path, Type t, JsonField jsonField, JsonValue jvalue)
   at FSharp.Json.Core.deserializeUnwrapOption@376(JsonConfig config, JsonPath path, Type t, JsonField jsonField, FSharpOption`1 jvalue)
   at FSharp.Json.Core.deserializeRecord@463(JsonConfig config, JsonPath path, Type t, JsonValue jvalue)
   at FSharp.Json.Core.deserializeNonOption@322(JsonConfig config, JsonPath path, Type t, JsonField jsonField, JsonValue jvalue)
   at FSharp.Json.Core.deserializeUnwrapOption@376(JsonConfig config, JsonPath path, Type t, JsonField jsonField, FSharpOption`1 jvalue)
   at FSharp.Json.Core.deserializeRecord@463(JsonConfig config, JsonPath path, Type t, JsonValue jvalue)
   at FSharp.Json.Core.deserializeNonOption@322(JsonConfig config, JsonPath path, Type t, JsonField jsonField, JsonValue jvalue)
   at Microsoft.FSharp.Collections.ArrayModule.MapIndexed[T,TResult](FSharpFunc`2 mapping, T[] array) in D:\a\_work\1\s\src\FSharp.Core\array.fs:line 453
   at FSharp.Json.Core.deserializeList@420(JsonConfig config, JsonPath path, Type t, JsonValue jvalue)
   at FSharp.Json.Core.deserializeNonOption@322(JsonConfig config, JsonPath path, Type t, JsonField jsonField, JsonValue jvalue)
   at FSharp.Json.Core.deserializeRecord@463(JsonConfig config, JsonPath path, Type t, JsonValue jvalue)
   at FSharp.Json.Json.deserializeEx[T](JsonConfig config, String json)
   at DeviantArtFs.Utils.thenMap@100.MoveNext()

Here is the problematic tier object in question:

            "tier": {
                "state": "active",
                "is_user_subscribed": false,
                "can_user_subscribe": true,
                "subproductid": 569102470,
                "dollar_price": "5.00",
                "settings": {
                    "access_settings": "all"
                },
                "stats": [],
                "benefits": [
                    "Welcome Gift!",
                    "Early Access to New Work",
                    "Over 2k Resolution Images"
                ]
            },

As you can see, despite documentation mentioning it can only be an object, for some reason they are returning array for stats and I guess that's why deserialization error is happening. I have also tested this with /deviation/#GUID# endpoint and it returns the same out of spec object, so this seems to be an issue in all of their api endpoints which return deviation object.

I'm not sure if you can do something about that, but I thought it's worth letting you know about this issue.

IsaacSchemm commented 2 months ago

Whatever serializer DeviantArt uses must (at least sometimes) render empty objects {} as empty arrays [] - I'm guessing whatever langauge they use on the backend doesn't distinguish between those two. I remember having an issue like that before.

I might just remove tier.stats from the model and add a note about it, unless you (or someone else) needs to use that for something.

AlexCSDev commented 2 months ago

I don't particularly need that, so feel free to remove it if that's the easiest way of dealing with that.

IsaacSchemm commented 2 months ago

Should be fixed in https://www.nuget.org/packages/DeviantArtFs/9.1.1