web services - Set Jackson DeserializationContext Attribute in per-request, thread-safe manner -
i'm looking able add request-scoped attribute (a jax-rs containerrequestcontext
because rather use jackson convert parameters objects jax-rs's ill conceived , clunky parameterconverterproviders
) deserializationcontext
can obtained within jsondeserializer
. must call convertvalue()
rather readvalue()
(not dealing actual json) not able create objectreader
in each thread unless willing serialize map json string first , read -which incredibly inefficient.
i'd able accomplishes following in per request manner:
objectmapper om = new objectmapper(); //in request-scoped context: om.getdeserializationcontext().setattribute("requestcontext",containerrequestcontext) map<string,object> mapofrequestparameters = ... beanofvastimportance bean = om.convertvalue(mapofrequestparameters,beanofvastimportance.class)
how can achieve without massive, superfluous overhead of needing create new objectmapper each individual request thread?
this can achieved by:
objectmapper.reader().fortype(request.class).withattribute("key", "value").readvalue("source")
Comments
Post a Comment