我正在嘗試使用郵件槍API獲取反彈郵件數據。Java客戶端消費API
public static ClientResponse GetBounce() {
Client client = new Client();
client.addFilter(new HTTPBasicAuthFilter("api",
"key-XXXXXXXXXXXXXXXXXXXXX"));
WebResource webResource =
client.resource("https://api.mailgun.net/v3/XXXXXXXXXXXX.mailgun.org/" +
"bounces/[email protected]");
return webResource.get(ClientResponse.class);}
它正常工作的API調用就可以了,但我不能ClientResponse轉換成合適的類型在我的CAE EmailError。從服務器 實際響應{"address":"[email protected]","code":"550","error":"550 5.2.1 The email account that you tried to reach is disabled. lq5si9613879igb.63 - gsmtp","created_at":"Tue, 18 Aug 2015 12:23:35 UTC"}
我創建POJO映射響應
@JsonAutoDetect(getterVisibility = Visibility.NONE, fieldVisibility = Visibility.ANY)
@JsonSerialize(include = Inclusion.NON_NULL)
public class EmailError {
private String address;
private String error;
private String created_at;
//geters...
//setters..
}
並嘗試ClientResponse映射到EmailError類型。
ClientResponse clientResponse = getBounce(email);
EmailError error = response.getEntity(new GenericType<EmailError>() {
});
其中clientResponse是方法GetBounce()
It throws an Exception com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class com.che.rt.businessservices.EmailError, and Java type class com.che.rt.businessservices.EmailError, and MIME media type application/json;charset=utf-8 was not found
任何猜測我很想念那裏的對象的回報。
顯示您的依賴。 –