camel jsonpath用于筛选具有路径的类名

camel jsonpath用于筛选具有路径的类名,json,apache-camel,jsonpath,Json,Apache Camel,Jsonpath,我用类过滤json类名的路径是 <route> <from uri="file:D:/inputFolder/jsonpath"/> <choice> <when> <jsonpath>$..com.mycompany.app10.Person</jsonpath> &l

我用类过滤json类名的路径是

        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>
在我的路径中,如果我在json路径中使用“$…Person”,并且我的输入是

        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>
{"com.mycompany.app10.Person":{"firstName":"Gregory","surname":"Smith","type":"FAMILY"}}
{“人”:{“名”:“格雷戈里”,“姓”:“史密斯”,“类型”:“家庭”}

        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>
它工作得很好

        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>

但是带有path的classname不起作用,是否有解决方法。

点是JSONPath表达式中的运算符。如果要将元素与其名称中的点进行匹配,如
com.mycompany.app10.Person
,则需要在表达式中转义点

        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>
$…Person
永远不会匹配
com.mycompany.app10.Person
。要匹配的元素是完全限定的类名。点是元素名的一部分,与JSON文档的结构无关

        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>
如果要匹配类名,需要将JSONPath表达式更改为
$..['com.my.company.app10.Person']
。或者
$['com.my.company.app10.Person']
,因为类名是根

        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>

另请参见关于JSONPath表达式中转义运算符字符的内容。

如果我使用建议的JSONPath表达式,如$..['com.my.company.app10.Person']或$['com.my.company.app10.Person']都不起作用,可能是Camel的实现?我在这里验证了它的工作原理:我用输入{“com.mycompany.app10.Person”:{“firstName”:“Gregory”,“姓氏”:“Smith”,“type”:“FAMILY”}检查了它不工作。你试过的输入是什么?我试过你在问题中提供的JSON,它成功了。
        <route>
            <from uri="file:D:/inputFolder/jsonpath"/>
            <choice>
              <when>
                <jsonpath>$..com.mycompany.app10.Person</jsonpath>
                <to uri="file:D:/inputFolder/jsonpath/output"/>
              </when>
            </choice>
        </route>