Arrays 如何在SpringXD中拆分传入的Json对象数组?

Arrays 如何在SpringXD中拆分传入的Json对象数组?,arrays,json,spring-xd,splitter,Arrays,Json,Spring Xd,Splitter,假设我的传入数据是一个json对象或json对象数组。 如果传入的json数据是一个数组,我想将其拆分,以便将它们插入MongoDB集合(为了简单起见,现在让我们登录到console) 定义流 xd:>streamcreatesplittest——定义“http | json到tuple | splitter | log”——部署 发布单个对象 xd:>HTTPPOST——数据“{\'dog\:\'chihuahua\”}” 21T09:05:59-0700 1.2.0.RELEASE INFO

假设我的传入数据是一个json对象或json对象数组。 如果传入的json数据是一个数组,我想将其拆分,以便将它们插入MongoDB集合(为了简单起见,现在让我们登录到console)

  • 定义流

    xd:>streamcreatesplittest——定义“http | json到tuple | splitter | log”——部署

  • 发布单个对象

    xd:>HTTPPOST——数据“{\'dog\:\'chihuahua\”}”

    21T09:05:59-0700 1.2.0.RELEASE INFO pool-44-thread-4 sink.splittest-{“dog”:“chihuahua”}

    这是预期的输出,因为输入是单个对象-没有要分割的对象

  • 发布对象数组

    xd:>HTTPPOST——数据“[{\'dog\':\'poodle\',{\'dog\':\'chihuahua\',{\'dog\':\'poodle\'”

    21T09:43:05-0700 1.2.0.RELEASE INFO pool-44-thread-11 sink.splittest-{}

    在本例中,我希望看到每行打印三个单独的狗对象,但它只打印一个空对象


  • 我做错了什么?有人能建议应该做什么吗?

    想出了怎么做的办法。我不需要费心使用json到元组处理器

    xd:>stream create splittest2 --definition "http | splitter --expression=#jsonPath(payload,'$.[*]') | log" --deploy
    
    xd:>http post --data "[{\"dog\": \"poodle\"}, {\"dog\": \"chihuahua\"}, {\"dog\":\"poodle\"}]"
    
    2015-10-21T10:52:31-0700 1.2.0.RELEASE INFO pool-83-thread-4 sink.splittest2 - {dog=poodle}
    2015-10-21T10:52:31-0700 1.2.0.RELEASE INFO pool-83-thread-4 sink.splittest2 - {dog=chihuahua}
    2015-10-21T10:52:31-0700 1.2.0.RELEASE INFO pool-83-thread-4 sink.splittest2 - {dog=poodle}
    
    所以它可以处理多个对象,但是,它不能像我预期的那样处理单个对象

    xd:>http post --data "{\"dog\":\"chihuahua\"}"
    2015-10-21T10:56:11-0700 1.2.0.RELEASE INFO pool-83-thread-10 sink.splittest2 - chihuahua
    

    我知道怎么做了。我不需要费心使用json到元组处理器

    xd:>stream create splittest2 --definition "http | splitter --expression=#jsonPath(payload,'$.[*]') | log" --deploy
    
    xd:>http post --data "[{\"dog\": \"poodle\"}, {\"dog\": \"chihuahua\"}, {\"dog\":\"poodle\"}]"
    
    2015-10-21T10:52:31-0700 1.2.0.RELEASE INFO pool-83-thread-4 sink.splittest2 - {dog=poodle}
    2015-10-21T10:52:31-0700 1.2.0.RELEASE INFO pool-83-thread-4 sink.splittest2 - {dog=chihuahua}
    2015-10-21T10:52:31-0700 1.2.0.RELEASE INFO pool-83-thread-4 sink.splittest2 - {dog=poodle}
    
    所以它可以处理多个对象,但是,它不能像我预期的那样处理单个对象

    xd:>http post --data "{\"dog\":\"chihuahua\"}"
    2015-10-21T10:56:11-0700 1.2.0.RELEASE INFO pool-83-thread-10 sink.splittest2 - chihuahua
    

    似乎,因为您的POST处理程序只处理一只狗,而不是一组狗,所以错误出现在处理POST请求的代码中,而不是发送所述请求的命令中。如果你发布这段代码,我会尽力帮助你。第二次发布返回200 OK,服务器没有抛出任何错误。它的打印完全如上图所示。而且没有代码可以这样做。我使用纯spring集成完成了这项工作,但我不想为SpringXD编写客户转换器和拆分器。我正在尽可能多地使用XD的开箱即用功能。很抱歉,我对Spring XD还不够熟悉,无法提供帮助。看来,由于您的POST处理程序只处理一只狗,而不是一组狗,所以错误在于处理POST请求的代码中,而不是发送所述请求的命令中。如果你发布这段代码,我会尽力帮助你。第二次发布返回200 OK,服务器没有抛出任何错误。它的打印完全如上图所示。而且没有代码可以这样做。我使用纯spring集成完成了这项工作,但我不想为SpringXD编写客户转换器和拆分器。我正在尽可能多地使用XD的开箱即用功能。对不起,我对Spring XD不太熟悉,无法提供帮助。也许这一个
    $…*
    ?足够接近了。它分割数组(这是我想要的)并分割每个dog.sink.splittest2-{dog=poodle}sink.splittest2-{dog=chihuahua}sink.splittest2-{dog=poodle}sink.splittest2-poodle sink.splittest2-chihuahua sink.splittest2-poodle可能是这一个
    $*
    ?足够近了。它拆分数组(这是我想要的),并拆分每个dog.sink.splittest2-{dog=poodle}sink.splittest2-{dog=chihuahua}sink.splittest2-{dog=poodle}sink.splittest2-poodle sink.splittest2-chihuahua sink.splittest2-poodle