2016-04-04 18 views
0

Webサービス内で入力JSONファイルを正しく読み込むのに問題があります。スプリングブートでJson文字列配列を取り込む方法

{ 
"inputParams" : { 
    "speckleFilter" : "filter1", 
    "acdChangeType" : "My_ACD", 
    "filterSize" : "7", 
    "aoi" : "[49.219181, 49.169297, -123.21575, -123.131194]", 
    "acdThreshold" : "", 
    "backScatScale" : "sigma" 
}, 
"inputData" : [ 
    { "stackId" : "1", 
     "state" : "new", 
     "uri" : "file:/C:/My/File/Name/", 
     "filterParams" : { 
      "aoi" : "[49.219181, 49.169297, -123.21575, -123.131194]", 
      "poi" : "", 
      "passDir" : "", 
      "sensorType" : ["sensor1"], 
      "contentType" : "[type1]", 
      "mediaType" : "[mediaType1]"}}, 
    { 
     "stackId" : "1", 
     "state" : "new", 
     "uri" : "file:/C:/My/File/Name/", 
     "filterParams" : { 
      "aoi" : "[49.219181, 49.169297, -123.21575, -123.131194]", 
      "poi" : "", 
      "passDir" : "", 
      "sensorType" : ["sensor1"], 
      "contentType" : "[type1]", 
      "mediaType" : "[mediaType1]"}}, 
    ] 
} 

Specificially、sensorTypeこのように読まれることはありません、と私は得る:私は私の入力JSONは次のようになります文字列

の配列に単純な文字列からいくつかの入力パラメータを変更しようとしていますここでエラー

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token\n 

は、私の要求ラッパークラスです:

public class FilterParams { 

private String passDir; 
private List<String> sensorType; 
private String aoi; 
private String mediaType; 
private String poi; 
private String contentType; 

public FilterParams(){ 
} 

public FilterParams(String passDir, List<String> sensorType, String aoi, 
        String mediaType, String poi,  String contentType){ 
    super(); 
    this.passDir = passDir; 
    this.sensorType = sensorType; 
    this.aoi = aoi; 
    this.mediaType = mediaType; 
    this.poi = poi; 
    this.contentType = contentType; 
} 

    //Getters and Setters.... 

} 

入力データ:

public class InputData { 

private String  stackId; 
private String  state; 
private URI   uri; 
private FilterParams filterParams; 

public InputData(){ 
} 

public InputData(String stackId, String state, URI uri, FilterParams filterParams) { 
    super(); 
    this.stackId  = stackId; 
    this.state  = state; 
    this.uri   = uri; 
    this.filterParams = filterParams; 
} 
    \\Getters and Setters 
} 

InputParams:

public class InputParams { 

private String speckleFilter; 
private String acdChangeType; 
private String filterSize; 
private String aoi; 
private String acdThreshold; 
private String backScatScale; 

public InputParams(){ 
} 

public InputParams(String speckleFilter, String acdChangeType, String filterSize, 
        String aoi,   String acdThreshold, String backScatScale) { 
    super(); 
    this.speckleFilter = speckleFilter; 
    this.acdChangeType = acdChangeType; 
    this.filterSize = filterSize; 
    this.aoi   = aoi; 
    this.acdThreshold = acdThreshold; 
    this.backScatScale = backScatScale; 
} 
    \\Getters and Setters 
} 

私のコントローラクラスがincomming JSONリクエストを解析する@RequestBodyを使用している:

@RequestMapping(value="/preprocessing", method = RequestMethod.POST) 
public ResponseEntity<PreProcessingResponse> doProcessing (@RequestBody PreProcessingRequest preProcessingReq){ 
    \\do important things 
} 

私は見て私のJSONファイルsensorTypeをフォーマットした場合contentTypeとmediaTypeと同じですが、JSONリクエストは簡単に解析されます。しかし、私は文字列の配列になるように変更したいと思っています(複数のオプションが有効なはずです)

私の問題を解決するために、FilterParamsクラス内のsensorTypeをList、ArrayList、JSONArray、 String []、List、おそらくもう少し私は今忘れてしまった。

私は、これらのオブジェクトが春の@RequestBodyアノテーションでどのように解釈されているかについて完全に誤解していることは明らかです。誰かが私に少しこれを明確にするのに役立つでしょうか? sensorType属性を文字列の配列に変更できないのはなぜですか?

この全体のドメインは私にとって新しいものです(これまで私がJavaでプログラミングしたことはありません)。ですから、何かが明確でない場合は私にお知らせください。私は明確にするために最善を尽くします。

ご協力いただきありがとうございます。

+0

Googleでのエラーを検索する最初の結果:http://stackoverflow.com/questions/14588727/can-not-deserialize-instance-of-java-util-arraylist-out-of-value-文字列 – farvilain

答えて

0

@RequestBodyはJSONをPOJOに変換するためにJacksonライブラリを使用します。これがあなたを助けてくれると願っています

Jersey: Can not deserialize instance of ArrayList out of String

+0

上記のリンクが直接役に立ちませんでしたが、私の実際のJSONファイルに問題が見つかりました:(私の経験不足は、この瞬間に本当に輝きました。 –

関連する問題