Ionic Push APIにメッセージを送信しようとしていますが、Json本体を正しく構築しましたが、「要求タイプ[com。」のHttpMessageConverterが見つかりませんでした。 amazonaws.util.json.JSONObject]」を選択します。RestTemplate Java Spring、適切なHttpMessageConverterおよび422 UnprocessableEntity
HttpMessageConverterを追加すると、Ionicから422 UnprocessableEntityが返されます。
ここでは、コード(コメント内のコードがMessageConverterです)です:
// MappingJackson2HttpMessageConverter jsonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
// jsonHttpMessageConverter.getObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// template.getMessageConverters().add(jsonHttpMessageConverter);
headers.add("Authorization", "Bearer <MY API KEY>");
headers.add("Content-Type", "application/json");
String pushMessage = "From : " + notification.getFrom().getNickname() + " Type : " + notification.getNotificationType();
JSONObject body = new JSONObject();
JSONObject message = new JSONObject();
JSONArray deviceTokens = new JSONArray();
try {
deviceTokens.put("DEV-75c960b5-fa90-4da7-b7df-8c1a01f80bdb");
message.put("message", pushMessage);
body.put("notification", message);
body.put("profile", "dev_push");
body.put("tokens", deviceTokens);
} catch (JSONException e) {
e.printStackTrace();
}
template.exchange("https://api.ionic.io/push/notifications", HttpMethod.POST, new HttpEntity<>(body, headers), String.class);
私はリクエストのボディだからイオン
{
"notification": {
"message":"From : mathijs0032 Type : like"
},
"profile": "dev_push",
"tokens": ["DEV-75c960b5-fa90-4da7-b7df-8c1a01f80bdb"]
}
によって設定された構造と一致していることを知って、デバッグからは、問題はおそらくHttpMessageConverterですか?