java - Extract specific field from json and deserialize it according to speicific Class<?> -
i have piece of json string extract specific fields, , field exist deserialize specific type (class).
so far have tried using objectmapper, problem it designed work in way input json value mapped designated class type. , in case need take specific fields out of json string , deserialize them objects.
next, i've tried jsonparser, offers more options since can iterate on json field-by-field , each field phone call 'readvalueas' method. perfect me, problem don't want go on json field-by-field, dynamically tell parser field parse , deserialize object.
here illustration of achieve:
say have json { "name" : "bob", "age" : 21, "status" : false }
i extract "name"'s value (bob) , deserialize java.lang.string
how can this??
edit: seek describe flow better: when app first loads read arguments of specific method using reflection, later when app receives json message parse message in way every key in json corresponds 1 arguments of method. need deserialize value of key json object matches argument.
if know reflection mechanism in java-8 can type of argument it's name wrote in code!
hope create clearer....not sure :-)
eventually i've found reply help i've received!!!
the right method of doing needed objectmapper#convertvalue, takes object , homecoming object of type class. in 2 steps: 1st convert object json representation , 2nd step serializing class.
java json jackson mongo-jackson-mapper
No comments:
Post a Comment