I'm porting a legacy API to Java from a Ruby app that takes full advantage of not being statically typed.
In one such situation, the API accepts from the JSON body a user_id that is either a numeric user ID or the string "me", (which should be converted to the ID of the user making the request before being saved to the database). The method looks like this:
@PUT
@Path("{key}")
@UnitOfWork
public Response getMyObjByKey(@PathParam("key") String key, MyObj myObj) {
myObjDAO.save(myObj);
}
I have a converter that I want to look something like this:
public class UserIdConverter extends StdConverter<String, Integer> {
@Inject
@AuthUser
protected AuthenticatedUser user;
public Integer convert(String strUserId) {
// if strUserId is "me"
return user.getId();
}
}
Of course, this doesn't work because of...something to do with the lifecycle that causes user to be null.
My question is: Is there a way for me to access the user object in the converter?