代码之家  ›  专栏  ›  技术社区  ›  Ash_s94

返回JsonNode时使用Swagger

  •  0
  • Ash_s94  · 技术社区  · 7 年前

    我目前编写了一个Spring引导应用程序,它在REST调用中返回一个Response对象(我创建的类)。它工作得很好,直到我合并了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>
    

    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。它显示耗时和命中率字符串。有人知道怎么解决这个问题吗?谢谢。

    0 回复  |  直到 7 年前