IceCubesApp icon indicating copy to clipboard operation
IceCubesApp copied to clipboard

Fixed non-existing Json key decoding error

Open mofmofmofneko opened this issue 2 years ago • 1 comments

The relationship endpoint of the instance to which I belong is as follows, and the notification key does not exist.

   {
      "id":"1",
      "following":true,
      "showing_reblogs":true,
      "followed_by":false,
      "blocking":false,
      "blocked_by":false,
      "muting":false,
      "muting_notifications":false,
      "requested":false,
      "domain_blocking":false,
      "endorsed":false,
      "note":""
   }

Decoding this will result in an error. So I tried decoding while checking if the key exists.

mofmofmofneko avatar Feb 13 '23 15:02 mofmofmofneko

Interesting, the API documentation does not show this as nullable.

sothawo avatar Feb 13 '23 17:02 sothawo

Not sure how I want to handle it. I don't like custom decoder... but I don't like making bool values optional.

Dimillian avatar Feb 13 '23 19:02 Dimillian

What about having a model with nullable property to be used in decoding and then the "real" model that can be initialized from the first one that will set defaults on missing values?

sothawo avatar Feb 13 '23 19:02 sothawo

Then I think I would prefer the custom decoder solution provided here :p

Dimillian avatar Feb 13 '23 20:02 Dimillian

Interesting, the API documentation does not show this as nullable.

The server version of my instance was 3.2.1. According to the API documentation, the notify key was added in 3.3.0.

mofmofmofneko avatar Feb 14 '23 08:02 mofmofmofneko

@Dimillian

As mentioned above, unless the version by the server is the latest, a decode error will occur because the key does not exist.

In terms of display, when I open the instance I belong to in the App, the follow list page remains loading and does not progress.

In order to deal with this problem and eliminate the version difference between servers, I would like to check the existence of the key before decoding. How about my fix?

mofmofmofneko avatar Feb 14 '23 08:02 mofmofmofneko