Alternative to a MultiValueMap for RESTful POST?

827 views
Skip to first unread message

Marco Cirillo

unread,
May 14, 2014, 1:04:58 PM5/14/14
to androidan...@googlegroups.com
I am trying to consume a RESTful API using AA. My API receives email and password request parameters (not JSON!) and returns an APIKey (which I use Jackson2 to deserialize).

Ideally, I want to use a regular old Map<String, String> to send the email and password, but it appears AA requires me to use a MultiValueMap (which is a Map<K,List<V>>), or a custom class (Event, which has no source shown).

When using a MultiValueMap, an array is sent. I am not sending an array of email and passwords, I am sending a single email and password:
// LoginFragment.java            
MultiValueMap<String, String> credentials = new LinkedMultiValueMap<String, String>();
credentials
.add("email", email);
credentials
.add("password", password);

// UserRest.java
@Post("user/login")
public APIKey login(MultiValueMap credentials);

Which trips up my API, because it expects a String rather and an array of Strings.

So I'm thinking I have to create a custom Credentials object to hold my email and password, and somehow get it serialized to be sent to the server. Could someone help me out with this?

Nico Küchler

unread,
May 15, 2014, 2:41:03 AM5/15/14
to androidan...@googlegroups.com
How you self named it, you want request parameters,. What you introduced is interpreted to request body.
So you like to have user and password as request parameters, then write what you want and use placeholders how it is mentioned at AndroidAnnotations cookbook.

@Post("user/login?email={email}&password={password}")

read also:

Marco Cirillo

unread,
May 21, 2014, 2:33:35 PM5/21/14
to androidan...@googlegroups.com
I'm not sure I follow. What I would like to do is have email and password sent in the request body. I don't believe it's secure to be throwing email addresses and passwords in the parameters.

Jan Lippert

unread,
May 21, 2014, 2:43:49 PM5/21/14
to androidan...@googlegroups.com

I'm on mobile, so I'll make it short. the following should work if you correct the syntax. by the way there's also authentification via HTTP headers - just for completeness, I did not try that out yet.

Jan

public class MyLogin{
String email;
String pwHash;
}

@Rest
public interface API{
// put everything in body
@post
void doLogin(MyLogin ml);
}

--
You received this message because you are subscribed to the Google Groups "androidannotations" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidannotati...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marco Cirillo

unread,
May 22, 2014, 1:18:33 PM5/22/14
to androidan...@googlegroups.com
Thank you Jan! A simple POJO like the one you provided indeed works. I was thinking I needed to handle annotating/serializing MyLogin myself, meanwhile it is dead simple!
Reply all
Reply to author
Forward
0 new messages