c# - JSON how to ignore missing object during deserialization -


i have sample json when deserialize "object reference not set instance of object" because found out field missing reappear again.

the json similar this

{     "title": "example",     "type": "object",     "properties": {         "firstname": {             "type": "string"         },         "lastname": {             "type": "string"         },         "age": {             "description": "age in years",             "type": "integer",             "minimum": 0         }     }  } 

if deserialize , map corresponding fields result ok

but if example "age" missing

{     "title": "example",     "type": "object",     "properties": {         "firstname": {             "type": "string"         },         "lastname": {             "type": "string"         },     },     "required": ["firstname", "lastname"] } 

it throw error "object reference not set instance of object" how ignore age if it's missing in json?


update when said using json.net

i there setting json.net try below

jsonserializersettings.nullvaluehandling = nullvaluehandling.ignore 

if real poco object, check if property there null, assigned blank object. like

if(myobject.properties.age==null) {    myobject.properties.age = new age(); } 

then deserialize it.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -