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

springwebclient:Parse+Stream非常大的JSON

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

    这个问题类似于 Spring reactive streaming data from regular WebClient request 不同的是,我不会立即从我的WebClient中获取JSON数组,而是类似这样的内容:

    这个JSON对象可能非常大(约100MB),因此需要对其进行处理并流式传输到客户端,而不是解析。这是我似乎能够正确理解语义的唯一方法:

    {
       "result-set":{
          "docs":[
             {
                "id":"auhcsasb1005_100000"
             },
             {
                "id":"auhcsasb1005_1000000"
             },
             {
                "id":"auhcsasb1005_1000001"
             },
             {
                "id":"auhcsasb1005_1000002"
             },
             ...
             ...
             {
                "EOF":true
             }
          ]
       }
    }
    
    WebClient.create()
      .get()
      .retrieve()
      .bodyToMono(DontKnowWhatClass.class)
      .flatMapMany(resultSet -> Flux.fromIterable(resultSet.getDocs()))
    

    但这意味着我要在内存中反序列化100MB或更多,然后从中创建流量。我想知道的是:我错过了什么重要的东西吗?我能从这样的物体中创造出一个通量吗?遗憾的是,我现在有办法影响结果集对象的渲染方式。

    0 回复  |  直到 6 年前