JsonObject, NoSuchMethodException, and null

21 views
Skip to first unread message

Christopher Piggott

unread,
May 17, 2013, 9:07:16 PM5/17/13
to mi...@dartlang.org
Hi,

I'm having great success with using JsonObject to map to static types in my interface layer.  One thing is giving me a headache, though.  My objects have a number of fields that may be omitted from the JSON that goes over the wire.  In these cases, I can't do this:

if( myObject.something != null)  {
   doSomethingWithIt
();
}


because of the exception.  I have to wrap all those with:

try {
   
if(myObject.something !+ null) { doSomethingWithIt();  }
} catch (NoSuchMethodException) {
}


It's kind of messy, and I'm looking for a better way.  I considered making non-existing objects default to null by extending JsonObject.

What do others do with sparse json objects with lots of optional fields?

--Chris

Reply all
Reply to author
Forward
0 new messages