I'm trying to implement a webapp that has, among other things, Users. Via the web, my customers need to be able to register (create users with some amount of validation), login, look themselves up, make changes. Typical stuff.
I see the user example in github (
https://github.com/baratine/baratine/tree/master/examples/user) and find it baffling. It's far more complex than any of the Getting Started or Tutorial stuff.
So, working from the Getting Started and Tutorial examples, I'm trying to do something like this:
@Service
public
class
App
{
@Post("/users")
public
void
createUser(@Body User inUser,
RequestWeb inRequest)
{
System.out.println("User: " + inUser.login + ", first: " + inUser.first + ", last: " + inUser.last);
inRequest.status(HttpStatus.CREATED);
inRequest.ok(inUser);
}
public
static
void
main(String[] inArgs)
throws
Exception
{
Web.include(App.class);
Web.go(inArgs);
}
}
And I hit that with:
curl -vv -X POST "
http://localhost:8080/users" -H "Content-Type: applicatation/json" --data '{"first":"First","last":"Last","email":"m@m.c","password":foo","login":"first"}'
But I get an exception:
java.lang.IllegalStateException: Unknown body type: class com.latencyzero.hoa.User
Now, I have a super-simple User class in there, too (all my code compiles):
public
class
User
{
String login;
String hashedPassword;
String first;
String last;
String email;
}
So, what am I missing?
Followup question: If Baratine is going to create my User object for me, well, that in some ways doesn't work. I never want the User object to have a clear-text password in it, nor do I want a field for that. But I do want to be able to include one in the JSON that's posted. In my user creation processing, I want to hash the password and store that (by the way, that strikes me as something that should be done asynchronously, right?).
So, do I need to create some *other* User object which would be the fields of the expected JSON payload? Is there another way to get individual field values out of a JSON body? I tried [@Body("login") String inLogin] as a parameter to my createUser() method, but it threw an exception saying it expected a form-encoded body. I don't see any reason why the body can't be JSON, especially with the Content-Type set.
--
Rick Mann
rm...@latencyzero.com