0

conclusion

never mind. the fields are marked as optional in the spec. it was late. sue me.

the q is left for reference


What is coming out:

  {
   "tags": [
    "cakephp",
    "fileupload",
    "file-get-contents"
   ],
   "answer_count": 0,
   "favorite_count": 0,
   "question_timeline_url": "/questions/3078600/timeline",
   "question_comments_url": "/questions/3078600/comments",
   "question_answers_url": "/questions/3078600/answers",
   "question_id": 3078600,
   "owner": {
    "user_id": 371434,
    "user_type": "unregistered",
    "display_name": "Nick",
    "reputation": 1,
    "email_hash": "2960026756b3103492382b68085207bd"
   },
   "creation_date": 1277021683,
   "last_activity_date": 1277021683,
   "up_vote_count": 0,
   "down_vote_count": 0,
   "view_count": 0,
   "score": 0,
   "community_owned": false,
   "title": "How to retrieve contents from a uploaded file."
  }

Missing:

accepted_answer_id;
bounty_amount;
bounty_closes_date;
closed_date;
closed_reason;
migrated;
protected_date;

if these are omitted as nullable you should consider javascript clients that depend on a value to avoid extreme code bloat and performance hits in doing undefined checks on every expected field.

and if they are being omitted as nullable, why then are not the other 0 fields being rendered. Don't get me wrong, I want the structure rendered as advertised, just asking the logical next question.

0

1 Answer 1

2

There's a distinction to be made between fields that are empty and those with a default value.

score, for instance, is by default 0. It always has a value, conceptually anyway, so it is never omitted.

accepted_answer_id is empty by default. Thus it is not returned, rather than filled with a 0 or -1 or whatever.

I'd also point out that its basically exactly the same amount of code in javascript to check against a default value and the absence of a value.

if(question.accepted_answer_id == -1) ...

versus

if(question.accepted_answer_id == undefined) ...

Our current scheme is slightly better in terms of bandwidth, and much better in terms of conceptual integrity. Omitted fields in a return are undefined fields on the server object.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .