是否有可以在Json中解析的数据限制?

问题描述 投票:-1回答:1

当json文档中的一个字段包含太多字符(用超过16K字符测试它)时,我得到一个解析错误。如果我删除该字段中的数据,一切都很完美。

我的代码对端点执行GET,该端点返回带有对象数组的JSON文档。如果其中一个对象(假设数组中的数字119)在其中一个字段中有太多字符(恰好是html代码),我会得到以下异常:

Could not read document: Connection reset (through reference chain: Object[][119]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Connection reset (through reference chain: Object[][119])

正如我所说,删除该字段的内容或使其成为正常大小的字符串使其工作。我不相信有连接重置错误,因为对其他端点(没有那么大的字段)的请求工作正常。

我使用Spring的REST模板,我尝试用Gson替换Jackson映射器,但是我得到了完全相同的行为,并且稍有不同的错误消息(Gson没有指定数组的元素)。更具体地说,我取而代之:

List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new MappingJackson2HttpMessageConverter());        
    this.restTemplate.setMessageConverters(messageConverters);

有了这个:

List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
        GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
        messageConverters.add(converter);
        this.restTemplate.setMessageConverters(messageConverters);

那么,JSON中的字段是否可以存储和解析数据/字符是否有限制?如果是这种情况,我该如何配置该限制?还有另一种方法可以实现这一目标而不受限制吗?


这是请求的示例:

http://api.myServer.com:8080/api/v1/categories
GET
Headers: 
Content-Type: application/json
Authorization: Basic xxxxxxxxx

这是响应的一个例子:

[
{
    "category_id": "C1",
    "name": "Category 1",
    "short_name": "Cat 1",
    "description": "Description of the category"

},
{
    "category_id": "C2",
    "name": "Category 2",
    "short_name": "Cat 2",
    "description": "very long string, usually well-formed HTML"

},
.
.
.
.
]

我将JSON doc作为响应(使用Postman)存储到文本文件中,其大小为2.29 MB。

java json jackson gson resttemplate
1个回答
0
投票

谜团已揭开!或者......

结果证明这是一个基础设施问题。我们使用Tierpoint托管我们的服务器,并且防火墙设置不允许超过2MB的响应。至少那是IT人员在我升级问题时向我解释的方式。

谢谢大家的帮助。至少我能够确认在JSON中要解析的数据量没有限制。

© www.soinside.com 2019 - 2024. All rights reserved.