使用Swagger-Spring-Java时,@pathvaria中的重音字符无法正确解码



我正在使用swaggerui来删除我的春季应用程序。在我的配置类中,我有:

@Configuration
@EnableCaching
@EnableScheduling
@PropertySource({ ...})
public class AppConfig{
....
@Bean
public FilterRegistrationBean filterRegistrationBean() {
    CharacterEncodingFilter filter = new CharacterEncodingFilter();
    filter.setEncoding("UTF-8");
    filter.setForceEncoding(true);
    FilterRegistrationBean registrationBean = new   FilterRegistrationBean();
    registrationBean.setFilter(filter);
    registrationBean.addUrlPatterns("/*");
    return registrationBean;
} 
...
} 

在我的控制器中,我有:

    public MyreturnedObject myMethod(@ApiParam(value = "myPathParam code of user that needs to fetch the returnedObjects", required = true) @PathVariable final String myPathParam{
...
}

当我将Swaggerui与参数值一起使用EX:xxéxx我在请求URL中获得Swaggerui:

https://localhost/myApi/XX%C3%89XX/returnedObjects?...

在我看来,在UTF-8中正确解码。在我的调试器(我正在使用RAD和WebSphere)中,我得到了:xxãxx,这是错误的值。谁能帮助指出我在做什么错,并告诉我如何解决这个问题?

编辑

我注意到的是,swaggerui中的代码在utf中为é= c3 89中的代码中的代码,但这两个部分以某种方式解码为空字符,就好像是在unicode中解码的,其中c3 =ã89 =没有此链接中所示的内容。

我找到了一个解决方法,帮助我解决了问题。在我的控制器调用的服务中,我创建了一个方法如下

public String myServiceMethod (String myPathParameter) {
       String encodedUTF8 = null;
       try{
           byte[] utf8 = myPathParameter.getBytes("ISO-8859-1");        
           encodedUTF8 = new String(utf8, "UTF8");
           return encodedUTF8;
       }
       catch(java.io.UnsupportedEncodingException e){
         // logger that states that the encoding went wrong
       }
}

我说的只是解决方法,因此,如果有更好的答案(有些春季设置可以让我以干净的方式进行此操作),我将非常感谢。

最新更新