返回JsonNode时使用Swagger

时间:2018-10-12 15:22:45

标签: java spring-boot swagger swagger-ui swagger-2.0

我目前已经编写了一个Spring Boot应用程序,该应用程序在其中一个REST调用中返回一个Response Object(我创建的类)。一切正常,直到我合并了Swagger,现在出现以下错误:

<Response>
    <timeTook>69</timeTook>
    <hitsCount>138</hitsCount>
    <hits>
        <hits>
            <msg>
                <Map>
                    <timestamp>1539357450970</timestamp>
                    <status>200</status>
                    <error>OK</error>
                    <message>Could not write JSON: Invalid white space character (0x1) in text to output (in xml 1.1, could output as a character entity); nested exception is com.fasterxml.jackson.core.JsonGenerationException: Invalid white space character (0x1) in text to output (in xml 1.1, could output as a character entity)</message>
                    <path>/api/messagesearch/1.0/search</path>
                </Map>

这是我用来创建Response对象的Response类。

public class Response {

    private String timeTook;
    private String hitsCount;
    private List<JsonNode> hits;

    public Response(String took, String hitsCount, List<JsonNode> hits){
        this.timeTook = took;
        this.hitsCount = hitsCount;
        this.hits = hits;
    }

    public String getTimeTook() {
        return timeTook;
    }

    public String getHitsCount() {
        return hitsCount;
    }

    public void setHitsCount(String hitCount) {
        this.hitsCount = hitCount;
    }

    public void setTimeTook(String timeTook) {
        this.timeTook = timeTook;
    }

    public List<JsonNode> getHits() {
        return hits;
    }

    public void setHits(List<JsonNode> hits) {
        this.hits = hits;
    }
}

在我看来,Swagger并不特别喜欢JsonNodes的使用。它显示了timetook和hitCount字符串。有人知道如何解决此问题吗?谢谢。

0 个答案:

没有答案