Mailgun API のラッパーを作成するために、jackson で netflix-feign を使用しています。問題は、API が POST 要求を使用する必要があることです。"Content-Type: application/x-www-form-urlencoded"
これはサンプルコードです:
@RequestLine("POST /messages")
@Headers("Content-Type: application/x-www-form-urlencoded")
ResponseMessage sendMessage(Message message);
Message
オブジェクトには必要なプロパティが含まれており、JSON アノテーションがあります
。@JsonProperty(value = "from")
private String from;
問題は、送信されるオブジェクトが JSON オブジェクトであることです。
{
"from" : "test@test.mailgun.org",
"to" : "atestaccount@gmail.com",
"subject" : "A test email",
"text" : "Hello this is the text of a test email.",
"html" : "<html><body><h1>Hello this is the html of a test email.</h1></body></html>"
}
ただし、これは有効なx-www-form-urlencoded
コンテンツ タイプではありません。
オブジェクトを正しいコンテンツ タイプに自動的にシリアル化する方法はありますか?
@Body
アノテーションを使用できると思いますが、それを使用するには、さまざまなプロパティをsendMessage
メソッドに渡す必要があります。