我正在尝试使用Spring for Android rest client
, 来发送数据http post
,以避免创建和解析 json 数据。
从他们的手册中,他们有以下方法:
restTemplate.postForObject(url, m, String.class)
调用该方法后,我得到以下异常:
No suitable HttpMessageConverter found when trying to execute restclient request
我的活动代码片段是:
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
Message m = new Message();
m.setLibrary("1");
m.setPassword("1395");
m.setUserName("1395");
String result = restTemplate.postForObject(url, m, String.class);
消息对象是:
public class Message {
private String UserName, Password, Library;
public String getUserName() {
return UserName;
}
public void setUserName(String userName) {
UserName = userName;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
public String getLibrary() {
return Library;
}
public void setLibrary(String library) {
Library = library;
}
}
为什么不能呢convert the Message object to JSON
?