相关疑难解决方法(0)

如何使用Spring-Web中的RestTemplate解析gzip编码的响应

在我修改了一个RESTful Web服务示例以从api.stackexchange.com 调用来自id的用户之后,我得到了JsonParseException:

com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens

响应来自api.stackexchange.comgzip压缩.

如何在Spring-Web RestTemplate中添加对gzip压缩响应的支持?

我正在使用Spring boot parent ver.1.3.1.RELEASE因此Spring-Web4.2.4-RELEASE

这是我调整后的例子:

User.java

package stackexchange.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(LowerCaseWithUnderscoresStrategy.class)
public class User {

    // Properties made public in order to shorten the example
    public int userId;
    public String displayName;
    public int reputation;

    @Override
    public String toString() {
        return "user{" …
Run Code Online (Sandbox Code Playgroud)

spring resttemplate stackexchange-api spring-web

10
推荐指数
1
解决办法
1万
查看次数