Feature: Define actual type of Root Object (for serialization)

(see Jira entry JACKSON-264 for more details)

By default ObjectMapper.readValue() will instantiate a new bean (Map, Collection, array) object first, and then bind JSON data into that Object. This feature allows caller to define an Object that will get updated with bound JSON data, instead of a newly constructed object. This is most useful with beans, but works with Collections and Maps (but does NOT work with arrays -- this because array length can not be changed so they can not be fully supported).

You can do, for example:

  Bean myBean = new Bean();
  new ObjectMapper().updatingReader(myBean).readValue("{ \"lastName\" : \"Bar\" }");
  // basically equivalent to calling 'myBean.setLastName("Bar");', while leaving first name as is

Note that this operation does not do "deep" merges: properties of updated object are either left as is (if JSON data has nothing to reset them), or overwritten (if there is matching property i JSON).


JacksonFeatureUpdateValue (last edited 2010-03-23 06:37:04 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC