私のSpring MVCサーバーでは、ファイル(画像)といくつかのJSONメタデータの両方を含むマルチパート/フォームデータ要求を受け取る必要があります。 JSONセクションの内容がContent-Type=application/json
の整形式のマルチパートリクエストを作成できます。 春のサービスは形式である:マルチパート/フォームデータのJSONメッセージコンバータの追加
@RequestMapping(value = MY_URL, method=RequestMethod.POST, headers="Content-Type=multipart/form-data")
public void myMethod(@RequestParam("image") MultipartFile file, @RequestParam("json") MyClass myClass) {
...
}
ファイルが正しくアップロードされていますが、私はJSONの一部に問題を抱えています。私はこのエラーを取得する:
org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'myPackage.MyClass'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [myPackage.MyClass]: no matching editors or conversion strategy found
私は、マルチパートリクエストJSON変換がジャクソン2を使用しても動作しますが、マルチパートを使用しているとき、私は、以前のエラーを取得を使用しない場合。私は、メッセージの一部としてJSONをサポートするためにマルチパートメッセージコンバータを設定する必要があると思いますが、私はその方法を知らないのです。ここに私の設定です:私が代わりにMyClassのののMyClassの種類として文字列を使用する場合
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
すべてがうまく動作しますが、私は、パラメータ変換のためのSpring MVCのサポートを使用します。
私も同様の問題に直面していますhttp://stackoverflow.com/questions/18896648/json-post-spring-mvc-curl-400-bad-request – Pradeep