私は、@PUT
と@POST
メソッドを実装するJersey 1.19.1リソースを持っています。 @PUT
メソッドは、入力/要求本体としてJSON文字列を使用し、@POST
メソッドはプレーンテキストを受け取ります。 JSONマッピングの場合、私はJackson 2.8を使用しています。Jersey:ハードコードPOST/PUT ObjectMapper、Content-Typeヘッダなし
リソースがこのように動作するように定義されているので、クライアントがContent-Type
要求ヘッダーを指定する必要はありません。なぜなら、Jerseyは要求本体で使用するものを特定する必要があるからです。私が代わりに、「この@PUT
入力のため、このObjectMapper
を使用する」ジャージーを伝えることである、または「常にこの入力は、この方法でapplication/json
Content-Type
を持つことになりますと仮定します。」何をしたいです
@Produces(MediaType.APPLICATION_JSON)
@Path("/some/endpoint/{id}")
public class MyResource {
@PUT
public JsonResult put(
@PathParam("id") String id,
// this should always be deserialized by Jackson, regardless of the `Content-Type` request header.
JsonInput input
) {
log.trace("PUT {}, {}, {}", id, input.foo, input.bar);
return new JsonResult("PUT result");
}
@POST
public JsonResult post(
@PathParam("id") String id,
// this should always be treated as plain text, regardless of the `Content-Type` request header.
String input
) {
log.trace("POST {}, {}", id, input);
return new JsonResult("POST result");
}
}
私はthis answerを見つけましたが、そこに解決策は、クライアントが正しいContent-Type
ヘッダを追加するために必要な、またはそれ以外の場合は、手動でオブジェクトのマッピングを行うべきであるということのようだとして、それは、私が探しているものではないのです。