0

I generate yaml from one api method sourcecode with swagger-maven-plugin:

@ApiModelProperty(value = "Сенсоры устройства", example = "{\"BATTERY\":67, \"VOLUME\":50, \"AIRPLANE\":false, \"ALARM\":true, \"CHARGE\":false, \"MUTE\":false, \"SCREEN\":true, \"WIFI\":true, \"LOCATION\": {\"latitude\":55.78409222171274,\"precision\":65.0,\"time\":\"2017-09-29T14:55:00Z\",\"detectionTechnology\":\"GPS\",\"msisdn\":\"79851620850\",\"deviceId\":\"28255923\",\"longitude\":37.62893324268332}}")

In generated yaml I have:

example: "{\"BATTERY\":67, \"VOLUME\":50, \"AIRPLANE\":false, \"ALARM\":true,\
      \ \"CHARGE\":false, \"MUTE\":false, \"SCREEN\":true, \"WIFI\":true, \"LOCATION\"\
      : {\"latitude\":55.78409222171274,\"precision\":65.0,\"time\":\"2017-09-29T14:55:00Z\"\
      ,\"detectionTechnology\":\"GPS\",\"msisdn\":\"79851620850\",\"deviceId\"\
      :\"28255923\",\"longitude\":37.62893324268332}}"

After that I generate api method back to java with swagger-codegen-maven-plugin and got this:

@ApiModelProperty(example = "\"{\\\"BATTERY\\\":67, \\\"VOLUME\\\":50, \\\"AIRPLANE\\\":false, \\\"ALARM\\\":true, \\\"CHARGE\\\":false, \\\"MUTE\\\":false, \\\"SCREEN\\\":true, \\\"WIFI\\\":true, \\\"LOCATION\\\": {\\\"latitude\\\":55.78409222171274,\\\"precision\\\":65.0,\\\"time\\\":\\\"2017-09-29T14:55:00Z\\\",\\\"detectionTechnology\\\":\\\"GPS\\\",\\\"msisdn\\\":\\\"79851620850\\\",\\\"deviceId\\\":\\\"28255923\\\",\\\"longitude\\\":37.62893324268332}}\"", value = "Сенсоры устройства")

And more - in generated controller for tis api method I have another result:

"sensors" : \"{\\"BATTERY\\":67, \\"VOLUME\\":50, \\"AIRPLANE\\":false, \\"ALARM\\":true, \\"CHARGE\\":false, \\"MUTE\\":false, \\"SCREEN\\":true, \\"WIFI\\":true, \\"LOCATION\\": {\\"latitude\\":55.78409222171274,\\"precision\\":65.0,\\"time\\":\\"2017-09-29T14:55:00Z\\",\\"detectionTechnology\\":\\"GPS\\",\\"msisdn\\":\\"79851620850\\",\\"deviceId\\":\\"28255923\\",\\"longitude\\":37.62893324268332}}\"

here code is broken! \\" - is not valid sequence

1 Answers1

0

Backslashes are used to escape specifics characters, like ' " ' : end of the String or '\' : special character incoming.

Valentin M.
  • 520
  • 5
  • 19