I recently stumbled upon a problem that I could not find any references to although it's very unlikely nobody ever had this problem before.
Maybe someone can give me a heads-up on where to look.
Using JAX-RS to build a REST service running on JakartaEE 8 I created a method that's supposed to handle PUT requests from the client. This method is given a DTO object which, amongst other things, contains a HashMap
that uses Long
variables as keys.
This works just fine so far and the method accepts the input given by the clients PUT request.
However when I check for the type of the variables that the keyset()
method return for the HashMap
it is not of type Long
but instead of type String
which obviously leads to problems later on.
Here is a shortened version of the code in question:
@PUT
@Path("edituser")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Optional<DTOobject> editUser(@QueryParam("user_id") Long user_id, DTOobject dto_object) {
for (Object i : dto_object.getOtherDTO_map().keySet()) {
LOGGER.log(Level.INFO, "HashMap key of type: {0}", i.getClass().getName());
// This will return java.lang.String as the type for the individual keys.
}
// do something and return something
}
public class DTOobject {
// some other vars
private HashMap<Long, OtherDTO> otherDTO_map;
// getters and setters
}