Spring rest template json with square bracket

Viewed 29

it my first to handle json format with 2 square bracket. Im trying to get the value from the parameter in json. And i receive error can be seen below, already added @JsonFormat(shape = JsonFormat.Shape.ARRAY) to a class. hoping for solution its been days trying .

My other method is working but has no 2 array in the begging of json;

//receiving json from front end
[  
   [
    {
    "param1": "value1",
    "param2":"value2"

    }

  ]  
]
//pojo
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
public class testclassmain{
   List<testclass> testclass;
}
//pojo

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
public class testclass{

     @JsonProperty("param1")
    public String param1;
    @JsonProperty("param2")
    public String param2;

  

}
String url = localhost:samplesample/{id} //just a sample url not real

public List<testclassMain> testResult(String token, Integer id) {
        HttpHeaders headers = MethodBuildtoken.test(token); //not actual but has token
     

        Map<String, Integer> proMap = new HashMap<String, Integer>();
        proMap.put("id", id);

        testclassMain testmain = new testclassMain();
        

        HttpEntity<?> httpEntity = new HttpEntity<>(testmain, headers);

        ResponseEntity<testclassMain>  result = restTemplate.exchange(url, HttpMethod.GET, httpEntity, testclassMain.class,proMap);

 
        return Arrays.asList(result.getBody());

Error




// from Array value (token `JsonToken.START_ARRAY`)
// 
 Cannot deserialize a POJO ... from non-Array representation (token: VALUE_STRING): type/property designed to be serialized as JSON Array

(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('NO MATCHES FOUND') 
0 Answers
Related