1

I'm using RestTemplate in Spring 4.1.4 to post to a REST API which returns JSON. In one of the fields of the JSON response there is a value with square brackets, something like:

"blah [blah] blah"

When the response is serialised into my response object (a simple bean of Strings) the value is not written and appears as null.

Furthermore, when I just use a String as the response object the filed is still null.

Presumably something is going on in the Jackson HTTP Message converter or ObjectMapper but I can't figure out why.

If I use a client like PostMan then the value is populated correctly. Also, for responses in the same field that don't contain square brackets all is fine also.

Anyone know of any gotchas?

Sample Code:

public SearchResults getSearchResults(final SearchRequest searchRequest) {
    SearchResults searchResult = null;
    try {
        searchResult = restTemplate.postForObject(searchRestUrl, searchRequest, SearchResults.class);
    } catch (HttpClientErrorException e) {
        //TODO
    }
    return searchResult;
}

Sample json: { "cars": [ { "carTypeID": 1, "carTypeName": "Taxi", "supplierCarTypeID": 1, "supplierCarTypeName": "Taxi [English (british)]", "supplierCarOptions": "Taxi", }, ] }

user1686402
  • 83
  • 1
  • 8

0 Answers0