5

Just found out that if you request a rant with the API and the rant doesn't contain an attached image, the 'attached_image' property defaults to an empty string, which is false, because an attached image is an object. This little thing screws up my code and I get exceptions all over the place D:

Mind fixing this? Or does anybody know how to tell Gson to allow an empty object field to be a string? Doesn't make a lot of sense though.

Comments
  • 0
    @dfox would be nice to get this fixed asap :D
  • 1
    I'm not sure I understand the problem. What would the expected value be?
  • 0
    Also wouldn't a check need to exist either way to see if attached_image is a non-false value?
  • 0
    @dfox {"id":124749,"text":"Just found out that if you request a rant with the API and the rant...","num_upvotes":1,"num_downvotes":1,"score":1,"created_time":1469821677,"attached_image": {},...}

    It should be an empty object, two curly braces. The request returns "", which means empty string.
  • 0
    @dfox It shouldn't come to a point where you need to check, not sure tho. If there is an object, the image exists, if not, the image doesnt. But returning an empty string is kinda against the API, because an image is defined as an object. So even the empty return value should be one.
  • 0
    @dfox But attached_image isn't a boolean value. Maybe I am getting it wrong tho. I am trying to map the son to Java Objects but the library messes me up. Image is defined as an object if it exists, so I mapped it to an Image class. But if there is no image, it is an empty string, which throws exceptions all over the place because the parser expects an object.

    Don't want to be cocky or anything like that but the parser is right at this point.
  • 0
    @SirWindfield I see what you're saying - this actually appears to be a bug (though it doesn't currently break anything). The expected behavior on our end, and what it seems he behavior was at some point, is there should be no attached_image on rants that don't have images.

    I'll revert to that behavior (no attached_image property when there's no image) once I can confirm it doesn't break anything in our apps and some other community-created ones. I'll let you know a bit later.
  • 0
Add Comment