Generated Swagger REST client does not handle + character correctly for query parameter

流过昼夜 提交于 2019-12-02 02:12:17

A + usually means a space in url params. This is a standard. Your url gets generated on below line of code

final BodyBuilder requestBuilder = RequestEntity.method(method, builder.build().toUri());

And + is not encoded as it is a valid value to have which will be then later converted to space at the receiving end. Now when you try use %2B the above line of code sees that you have a un-encoded % character and it converts it to %252B.

When you receive this back at Spring it converts it back to %2B for you. One way to solve the issue is to send encoded values yourself. So you will change

 final BodyBuilder requestBuilder = RequestEntity.method(method, builder.build().toUri());

to

final BodyBuilder requestBuilder = RequestEntity.method(method, builder.build(true).toUri());

And then call the API method as

client.myMethod("tarun%2blalwani")

And now spring will receive tarun+lalwani as shown below

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!