java - How can I detect if all JSON fields are being parsed? -
i using gson annotations parse json fields restful service dto. wanted write test detect if there fields in jsonobject not yet being parsed java dto object has annotations. if on server add ten fields have no way of knowing this? there way test dynamically if fields being parsed java object?
to put way, names of dto fields (including annotation info), , compare fields on json object. trying compare dto jsonobject see if have covered everything.
gson doesn't have this. "extra" fields in java or json silently ignored. fields present in java not in json set null
the way via reflection, either during gson's deserialization custom deserializer or parsing json jsonobject
using gson's jsonparser
class , doing test.
you'd need field names jsonobject
via entryset()
, field names java class using class.getdeclaredfields()
, compare 2 sets find ones not present in both.
Comments
Post a Comment