Storing null values in realm using Android -


previously, when there no stable version of realm java (android), not store null values in realm , had perform unnatural hack able so, explained in this post.

but of realm 1.0 released, there update being able store null value?

for example : unfortunate cases when there no field in json want store in realm after parsing haven't handled manually.

i have following code:

realmobject.setdata(jsonobject.getstring("selector")); 

the program flow stops , exits block code located inside.

the logcat shows

w/system.err: org.json.jsonexception: no value selector

but when do:

realmobject.setdata(null); 

the program flow not stop , continues across realm statement realmobject.setdata(null);

in cases, there no value tag "selector" in json file. , want null in default.

i found out problem :

jsonobject.getstring("selector") 

not whole statement:

realmobject.setdata(jsonobject.getstring("selector")); 

so fix me

realmobject.setdata(jsonobject.optstring("selector")); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo