7

OK I have a json say

userjson = { fname : "ABC", lname : "DEF" }

and a User Pojo Object

User {
 String id, 
 String email,
 String fname,
 String lname
}

now using the Jackson, I know how to create User instance from userjson, but how do i update existing User instance from userjson, because my user instance has some properties already set by some other Module.

For now what i am doing is converting userjson to userHasMap and then set all the values manually

userInstance.setFName(userHasMap.get('fname'))
userInstance.setLName(userHasMap.get('lname'))

which works fine, but I could have done some thing for converting userInstance to userjson when needed which would have made use of jackson-lib meaningless.

LNT
  • 876
  • 8
  • 18
  • As it is using json coming from JavaScript, anyway I removed it. – LNT Jun 04 '14 at 11:34
  • Why would somebody close it, without giving any reason? – LNT Jun 04 '14 at 11:35
  • What is the semantic difference? Wouldn't those "properties set by some other module" have to be updated as well? – Mikkel Løkke Jun 04 '14 at 11:40
  • yes but not in same thread or one go, yes are being updated if i want to use jackson to set what i will need to do is create temporary variables form existing one and then create new one and then set all those temps back to new One, its not lot of work and more importantly is that preferred? – LNT Jun 04 '14 at 11:47
  • It depends on your data structure. If the "properties set by some other module" are derived from the properties of the object, you should encapsulate them in that object. – Mikkel Løkke Jun 04 '14 at 11:57

1 Answers1

10

Ok found the answer, http://jira.codehaus.org/browse/JACKSON-857 http://jira.codehaus.org/browse/JACKSON-824

mapper.readerForUpdating(object).readValue(json);
LNT
  • 876
  • 8
  • 18