0

I am having trouble getting my an input JSON file to be read properly within my webservice. I am attempting to change some input parameters from a simple String to an array of Strings

my input JSON looks something like this:

{
"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 will not be read in this way, and I obtain an error

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

Here are my request wrapper classes:

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....

}

InputData:

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
}

My controller class is using @RequestBody to parse the incomming JSON request:

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

If I format my JSON file sensorType to look the same as contentType and mediaType then the JSON request is easily parsed. However, I would like to changed these attributed to be arrays of string (since more then one option should be valid)

To resolve my issue I have tried to declar the sensorType within the FilterParams class as List, ArrayList, JSONArray, String[], List, and probably a few more which I have now forgotten.

It is clear that I am completely misunderstanding how these objects are being interpreted with spring's @RequestBody annotation. Could someone help clear this up a bit for me? Why can I not just change the sensorType attribute to be an array of strings ?

This whole domain is rather new to me (I have never programmed in java before). So please let me know if something is not clear, and I will do my best to clarify.

Any help is much appreciated!

1

1 Answer 1

1

@RequestBody uses Jackson library to convert JSON to POJO. I hope this might help you.

Jersey: Can not deserialize instance of ArrayList out of String

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, for your response, while the above link did not help directly, I found an issue in my actual JSON file :( my inexperience really shined through in this moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.