1

Running a validation test and get these nasty characters embedded in the Swagger 2.0 validation output {"$ref":"#/definitions/DeferredResult«ResponseEntity«SummCollection»»"

Controller method returns: DeferredResult<ResponseEntity<SummCollection>>

I just noticed as I'm writing the question: Actual: "<" Crazy: "«"

Strange character in MockHttpServletRequest Swagger2 DeferredResult  response

This seems like an issue between "iso-8859-1" vs "utf-8" right? IDK.

Question is what is causing SwaggerTest validateImplementationAgainstDesignSpec to read the file .yaml json just fine, but the MockMvc performs GET the response is contains these "Â" characters between the class names and delimiters.

CODE CALL:

MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs?group=full-api") // 2 .accept(MediaType.APPLICATION_JSON) .characterEncoding("application/json;charset=ISO-8859-1")) .andDo(MockMvcResultHandlers.print()) .andExpect(status().isOk()) .andReturn();

I've debugged the code with the line .characterEncoding("application/json;charset=ISO-8859-1")) set to "UTF-8" and everything else in extreme (inclusive of "windows-1252"). This occurs on the Linux CI server, so it's not a winders thang.

I've read about it being a StringHttpMessageConverter issue/symptom, but to no avail as how to fix from using MockMVC to call for Swagger2.

OUTPUT:
MockHttpServletResponse: Status = 200 Error message = null Headers = {Content-Type=[application/json]} Content type = application/json Body = {"swagger":"2.0","info":{"description":"Some Description ","version":"1.0","title":"Sum-Server","license":{}},"host":"localhost","basePath":"/","tags":[{"name":"summ-service","description":"Summary Service"}],"paths":{"/api/v1/summ/{id}":{"get":{"tags":["device-summary-service"],"summary":"getDeviceSummaries","operationId":"getDeviceSummariesUsingGET","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"id","in":"path","description":"id","required":true,"type":"string"},{"name":"days","in":"query","description":"days","required":false,"type":"string"},{"name":"start","in":"query","description":"start","required":false,"type":"string"},{"name":"end","in":"query","description":"end","required":false,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/DeferredResult«ResponseEntity«SummCollection»»"}}}}}},"definitions":{"SummCollection":{"type":"object","properties":{"SummList":{"type":"array","items":{"$ref":"#/definitions/SummDateRange"}},"endDate":{"type":"string"},"prioritizedReportFamily":{"type":"integer","format":"int32"},"startDate":{"type":"string"}}},"DeferredResult«ResponseEntity«SummCollection»»":{"type":"object","properties":{"result":{"type":"object"},"setOrExpired":{"type":"boolean"}}}}}

ken
  • 666
  • 2
  • 6
  • 19

1 Answers1

3

Every time I do a question, waste hours, saying to myself, DON'T DO A STACK OVERFLOW, you almost have it. then in despair, finally write the question...

35 minutes later, find the answer.... simple one too. {ouch} See here: http://docs.spring.io/spring/docs/current/javadoc-api/index.html?constant-values.html

APPLICATION_JSON_UTF8_VALUE "application/json;charset=UTF-8" APPLICATION_JSON_VALUE "application/json"

the fix was:

.accept(MediaType.APPLICATION_JSON_UTF8_VALUE))

MediaType ! HA! Hope this helps somebody. :)

ken
  • 666
  • 2
  • 6
  • 19