0

How do I set the values of POJO properties that exist in both POJO and Map objects?

For example, I have this POJO class:

public class User {
   private int id;
   private String name;
   private String address;

   // getters/setters
}

User user = new User();
user.setId(1);
user.setName("Julez");
user.setAddress("Southwood City");

And I have this Map:

Map<String, String> map = new HashMap<>();
map.put("address", "Eastwood City");

Since User class has address, and Map has key address, I'd like to set the value of address as Eastwood City. There might be a possibility that the Map would also have key id, name, a combination of two or all of the User properties.

Edit: User object has already been created and all properties have values. In the above example, the address Eastwood City should be replaced by Southwood City.

Julez
  • 1,010
  • 22
  • 44
  • 1
    Possible duplicate of [Convert a Map to a POJO](https://stackoverflow.com/questions/16428817/convert-a-mapstring-string-to-a-pojo) – Sukhpal Singh Nov 26 '18 at 04:05
  • @GauravRai1512, pardon. I missed some important things. The `user` object should have been created and its properties have values, which means one or more of these properties would be updated depending on available key/value in the `map` object. – Julez Nov 26 '18 at 05:05

0 Answers0