我正在尝试使用 AA 使用 RESTful API。我的 API 接收电子邮件和密码请求参数(不是 JSON!)并返回一个APIKey
(我使用 Jackson2 反序列化)。
理想情况下,我想使用普通的旧Map<String, String>
来发送电子邮件和密码,但似乎 AA 要求我使用 a MultiValueMap
(即 a Map<K,List<V>>
)或自定义类(Event
,未显示源)。
使用 aMultiValueMap
时,array
发送 an。我不是在发送一系列电子邮件和密码,而是发送一个电子邮件和密码:
// LoginFragment.java
MultiValueMap<String, String> credentials = new LinkedMultiValueMap<String, String>();
credentials.add("email", email);
credentials.add("password", password);
APIKey resp = userRest.login(credentials);
// UserRest.java
@Post("user/login")
public APIKey login(MultiValueMap credentials);
这让我的 API 出错了,因为它需要一个字符串而不是字符串数组。
所以我想我必须创建一个自定义Credentials
对象来保存我的电子邮件和密码,并以某种方式将其序列化以发送到服务器。有人可以帮我解决这个问题吗?