Gravatar JSON Profile bug?
-
Hello there,
I believe i’ve stumbled on a Gravatar profiles bug. Normally you’d expect ‘name’ to be an object with ‘givenName’, ‘familyName’ etc. properties like in e.g.
https://en.gravatar.com/b701fb8a351a8a30adf58380edf2317c.json
However it seems that when ‘name’ is empty, the JSON serialization is an empty array like in e.g.
https://en.gravatar.com/fa24c69431e3df73ef30d06860dd6258.json
which is inconsistent and an issue for deserializers in strongly-typed languages, as one would expect null or an object with null properties instead.
I don’t have a site with WordPress.com yet
-
Hello there,
To check, are you referring to this line:
"name":{"givenName":"xxx","familyName":"xxx","formatted":"xxx"},"displayName":"xxx","currentLocation":"xxx, xxx","urls":[]}]}Out of curiosity, what led you to looking at this?
-
Hey Adam, thanks for the quick reply. Indeed: when non-null, “name” is an object like your example:
"name":{"givenName":"xxx","familyName":"xxx","formatted":"xxx"}but when unset, it’s an empty array like:
"name":[]this is a problem when using e.g. java or kotlin because one can’t normally de-serialize the property as “either” object or array and forces a dev to create a custom deserializer and related plumbing.
class User( val name: Name // cant be "Name || Array", needs special care }This came in as a bug report on my own codebase, no clue where they even got the email/hash from.
-
Thanks for that. It’s not clear to me whether this is by design or if it is a bug.
this is a problem when using e.g. java or kotlin because one can’t normally de-serialize the property as “either” object or array and forces a dev to create a custom deserializer and related plumbing.
Can you share some more details about that ^ ?
-
From e.g. kotlin’s point of view the JSON maps to either
class MyUser( val name: MyUserName }or
class User( val name: Array<String> }but you cant have both. So a custom component
CustomMyUserNameSerializeris needed to handle the type inconsistency according to the JSON library in use, e.g. jackson, kotlinx serialization or whatnot to create a null or emptyMyUserNamein case of an array for “name” in the JSON body.class MyUser( @CustomSerializer(CustomMyUserNameSerializer::class) val name: MyUserName } -
Thanks for that. I’ve passed this along to the folks who work on Gravatar and I’ll be back in touch once I hear from them.
-
I heard back from the team.
We have deployed a change that will omit the name property when it is empty (instead of rendering it as an empty array or empty object), which is in line with the current behaviour on profiles where a user hasn’t entered or has cleared out their first and last name fields.
-
- The topic ‘Gravatar JSON Profile bug?’ is closed to new replies.