I'm trying to use jersey's webtarget API to post json for an entity with nested properties, but it seems to be dropping the nested properties (but sending the others fine) in my http requests.
Here is my entity:
public class User {
private String username;
private String password;
private final List<Role> roles = new ArrayList<>();
}
with appropriate getters and setters
Role definition:
public class Role {
private Long roleId;
private String role;
}
also with getters and setters
I am making the http request like so:
User user = new User();
user.setUsername("name");
user.setPassword("password");
user.getRoles().add(new Role().setRole("somerole").setRoleId(1));
Entity<List<User>> body = Entity.json(Arrays.asList(user));
Response response = webTarget
.path("/multipleusers")
.request(MediaType.APPLICATION_JSON)
.post(body);
I logged the http call that's made. When the http call is executed, I noticed that the nested roles list object is completely dropped:
21-Oct-2021 12:05:06.457 INFO [http-nio-8080-exec-6] org.glassfish.jersey.logging.LoggingInterceptor.log 1 * Sending client request on thread http-nio-8080-exec-6
1 > POST https://example.com/multipleusers
1 > Accept: application/json
1 > Content-Type: application/json
[{"username":"name","password":"password"}]
How do I serialize nested objects/lists in my post request?