|
Page 1 of 1 |
|
Posted: Tue, 20th Nov 2018 11:52 Post subject: Get POJO Object from JSONPath |
|
 |
Let's say I have a simple POJO
Code: | public class Human() {
private List<Limb> limbs;
private HashMap<String, String> basicProperties;
private Date birthday;
private String name;
public static class Limb {
private String name;
private long length;
private String whatever;
... Getters and Setters;
}
... Getters and Setters;
} |
Now I can set and change values programatically by specifying f.e.:
Scenario 1: Setting the name of the human to dude
Code: | human.setName("dude");
|
Scenario 2: Setting the name of the limb with the name of "bla" to "blabla"
Code: | for(Limb limb: human.getLimbs())
if (limb.getName().equals("bla")){
limb.setName("blabla");
break;
}
|
I'd rather use a jsonpath though to set the values of my pojo.
So the call should rather look like uh...
Scenario 1:
Code: | setPOJOValue(human, "name", "dude");
|
Scenario 2:
Code: | setPOJOValue(human, "limbs[name='bla']", "blabla");
|
or...
Scenario 1:
Code: | human.setWithJson("name", "dude")
|
Scenario 2:
Code: | human.setWithJson("limbs[name='bla']", "blabla");
|
Any idea which library to use and how? I already have Jackson available. I'd rather not modify my POJO though and would like to use a function like my fictious setPOJOValue.
Thanks!
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
|
Posted: Tue, 20th Nov 2018 14:16 Post subject: |
|
 |
Jupp, has to be java. gson seems to have that but only to find the correct object in a passed json. So I would have to convert my pojo into json and then use gson to find the correct position, but I want to update the original java object... so that is not an option 
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|