camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Moulliard <ch0...@gmail.com>
Subject Re: Problems with jsonpath???
Date Thu, 28 Aug 2014 13:03:34 GMT
That will work if you build your choice expression like this

 from("websocket://0.0.0.0:8080/replication")
    .choice()
        .when()
.when(PredicateBuilder.isEqualTo(ExpressionBuilder.languageExpression("jsonpath","$.kind"),ExpressionBuilder.constantExpression("full")))

where json content is

{
    "kind": "full",
    "type": "customer"
}




On Thu, Aug 28, 2014 at 1:17 PM, Deven Phillips <deven.phillips@gmail.com>
wrote:

> Yeah, I looked for an example similar to my use case in their wiki, unit
> tests, etc... Thanks for asking them though!
>
> Deven
>
>
> On Thu, Aug 28, 2014 at 7:04 AM, Charles Moulliard <ch007m@gmail.com>
> wrote:
>
> > Raised a question to jsonpath google group as I don't know :
> > https://groups.google.com/forum/#!topic/jsonpath/MUNwbQ2UjTk
> > Unfortunately their code didn't cover this test case  ;-)
> >
> >
> > On Thu, Aug 28, 2014 at 11:57 AM, Deven Phillips <
> deven.phillips@gmail.com
> > >
> > wrote:
> >
> > > I tried that and I get:
> > >
> > >  com.jayway.jsonpath.PathNotFoundException: Path '@' not found in the
> > > current context:
> > > {"kind":"full"}
> > >
> > > I have tried a number of different permutations for that filter string,
> > but
> > > none have worked so far. Here are a few examples I have tried:
> > >
> > > $(@.kind == 'full')
> > > $.kind(@ eq 'full')
> > > $.kind(@ like 'full')
> > > $(@.kind like 'full')
> > > $(kind == 'full')
> > > $.kind == 'full'
> > >
> > > None of these match correctly. I have probably tried many others, but
> you
> > > get the idea.
> > >
> > > Thanks for trying!
> > >
> > > Deven
> > >
> > > On Thu, Aug 28, 2014 at 2:23 AM, Charles Moulliard <ch007m@gmail.com>
> > > wrote:
> > >
> > > > Your expressions does not look correct jsonpath("$(@.kind ==
> 'full'). I
> > > > think that it should be .jsonpath("$.@.kind == 'full'")
> > > >
> > > >
> > > > On Thu, Aug 28, 2014 at 5:03 AM, Deven Phillips <
> > > deven.phillips@gmail.com>
> > > > wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > >    As an example, I was using a simple JSON document:
> > > > >
> > > > > {
> > > > >     "kind": "full",
> > > > >     "type": "customer"
> > > > > }
> > > > >
> > > > > I wanted to use a jsonpath predictate in a choice route as shown
> > below:
> > > > >
> > > > >
> > > > > from("websocket://0.0.0.0:8080/replication")
> > > > >     .choice()
> > > > >         .when()
> > > > >             .jsonpath("$(@.kind == 'full')
> > > > >                 .log("Full update")
> > > > >         .otherwise()
> > > > >             .log("Not full update")
> > > > >
> > > > >
> > > > > The problem is that I could not get that to work with jsonpath...
I
> > did
> > > > > however get this workaround functional:
> > > > >
> > > > >
> > > > >         from("websocket://0.0.0.0:7080/replication")
> > > > >             .choice()
> > > > >                 .when()
> > > > >
> > > > > .javaScript("JSON.parse(request.body).kind.toLowerCase() ==
> 'full'")
> > > > >                         .log(LoggingLevel.INFO, "Full Update")
> > > > >                 .otherwise()
> > > > >                     .log(LoggingLevel.INFO, "Patch/Put");
> > > > >
> > > > > Any ideas as to why the jsonpath method is not working?
> > > > >
> > > > > Thanks in advance!
> > > > >
> > > > > Deven Phillips
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Charles Moulliard
> > > > Apache Committer / Architect @RedHat
> > > > Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
> > > >
> > >
> >
> >
> >
> > --
> > Charles Moulliard
> > Apache Committer / Architect @RedHat
> > Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io
> >
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message