java - Standard JSON representations -


we building webservice consumes , produces json.

problem: kind of confused how represent specific details of object.

example: specify empty element or null element null in json

the question ask our self how represent object when properties null.

example: car object , color , make properties, null.

we represent

car : {     "color": null,     "make" : null } 

some people argue should represented

car : null 

so lets say, car : null right way it. car not exact representation of domain object. piece of domain object, lets call big car. make car view object in kind of translator. find painful way of checking each field in car object , if null, set car null, jackson jaxb provider can render null. know that's not right way it.

can suggest alternative??

is there 1 place can check, there view object children null?? , set null.

which way more consumable??

if understand correctly there 3 different situations trying represent. 1 there no car, other there car don't know it, final 1 there car , know (perhaps it). there 3 possible situations:

(1) ricardo not have car

'ricardo': {   'car': null } 

(2) ricardo has car don't know it

'ricardo' : {   'car' : {     'color' : null,     'make' : null    }  } 

(3) ricardo has car , know (or everything)

'ricardo' : {   'car' : {     'color' : 'red',     'make' : 'ferrari'    } } 

you need sure of need model , representation accordingly. check here definitive reference.


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -