Hi,

Just posting my final findings to this.
My issue was caused by the fact i was using Jackson 2.9.4 which logged: Cannot 
writeAsString as adapter cannot be initialized.
When downgrading to 2.8.10 the writeAsString option worked perfectly, 
outputting a valid Json string, rather than the Map toString().

This might also explain the NoTypeConversionAvailableException.

Maybe something to add to the docs ;)

Thanks for the help, cheers!

- Joery

On 16 Feb 2018 16:55 +0100, Claus Ibsen <claus.ib...@gmail.com>, wrote:
> Hi
>
> It looks like your json is invalid / not structured well. You inner
> map uses duplicate ids, eg document.
> If possible use a array instead, eg [ ]
>
> See the unit test from the source code - JsonPathSplitWriteAsStringTest
>
> On Fri, Feb 16, 2018 at 10:44 AM, Joery Vreijsen <jhjvreij...@gmail.com> 
> wrote:
> > That indeed was my thought aswell, i tried the following route:
> >
> > from("file:src/data")
> > .split().jsonpathWriteAsString("$..document")
> > .setHeader(Exchange.FILE_NAME, new SimpleExpression("${exchangeId}.json"))
> > .to("file:target/messages/others”);
> >
> > But this resulted also in the following exception:
> >
> > No body available of type: java.io.InputStream but has value: 
> > {name=document 1, type=pdf} of type: java.util.LinkedHashMap on: Message[]. 
> > Caused by: No type converter available to convert from type: 
> > java.util.LinkedHashMap to the required type: java.io.InputStream with 
> > value {name=document 1, type=pdf}. Exchange[ID-local-1518795550966-0-3]. 
> > Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type 
> > converter available to convert from type: java.util.LinkedHashMap to the 
> > required type: java.io.InputStream with value {name=document 1, type=pdf}]
> >
> > I tried the route in the Spring DSL, and there the WriteAsString option 
> > worked, but outputted the .toString() value of the Map class, e.g. 
> > "{name=document 1, type=pdf}”.
> > Is there a possibility to let it output a valid json string, or is it just 
> > the Map toString function you can get back?
> >
> > Thanks again.
> >
> > Cheers!
> >
> > - Joery
> >
> > On 16 Feb 2018 16:37 +0100, Claus Ibsen <claus.ib...@gmail.com>, wrote:
> > > Ah okay yeah that can make sense to try to tell it to output as
> > > String. See the writeAsString option you would need to use
> > > https://github.com/apache/camel/blob/master/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc
> > >
> > >
> > >
> > > On Fri, Feb 16, 2018 at 10:30 AM, Joery Vreijsen <jhjvreij...@gmail.com> 
> > > wrote:
> > > > Hi Clause,
> > > >
> > > > Thanks for the quick response!
> > > >
> > > > When removing the String.class i get the following exception:
> > > >
> > > > No body available of type: java.io.InputStream but has value: 
> > > > {name=document 2, type=pdf} of type: java.util.LinkedHashMap on: 
> > > > Message[]. Caused by: No type converter available to convert from type: 
> > > > java.util.LinkedHashMap to the required type: java.io.InputStream with 
> > > > value {name=document 2, type=pdf}. 
> > > > Exchange[ID-local-1518794941554-0-5]. Caused by: 
> > > > [org.apache.camel.NoTypeConversionAvailableException - No type 
> > > > converter available to convert from type: java.util.LinkedHashMap to 
> > > > the required type: java.io.InputStream with value {name=document 2, 
> > > > type=pdf}]
> > > >
> > > > I was trying to split a Json without getting a Map POJO as return, but 
> > > > rather just a String value.
> > > >
> > > > Cheers,
> > > >
> > > > - Joery
> > > >
> > > >
> > > > On 16 Feb 2018 16:27 +0100, Claus Ibsen <claus.ib...@gmail.com>, wrote:
> > > > > Try without the String.class in the jsonpath
> > > > >
> > > > > On Fri, Feb 16, 2018 at 10:22 AM, Joery Vreijsen 
> > > > > <jhjvreij...@gmail.com> wrote:
> > > > > > Hi,
> > > > > >
> > > > > > I’m trying to split my following Json file with the Camel Splitter 
> > > > > > & JsonPath components.
> > > > > >
> > > > > > [
> > > > > > {
> > > > > > "document": {
> > > > > > "name": "document 1",
> > > > > > "type": "pdf"
> > > > > > }
> > > > > > },
> > > > > > {
> > > > > > "document": {
> > > > > > "name": "document 2",
> > > > > > "type": "pdf"
> > > > > > }
> > > > > > }
> > > > > > ]
> > > > > >
> > > > > > The route I’m using looks like this:
> > > > > >
> > > > > > from("file:src/data")
> > > > > > .split().jsonpath("$..document", String.class)
> > > > > > .to("file:target/messages/others");
> > > > > >
> > > > > > I expected two output files with contents similar to this:
> > > > > >
> > > > > > "document": {
> > > > > > "name": "document 1",
> > > > > > "type": "pdf"
> > > > > > }
> > > > > >
> > > > > > Strangely enough i got 4 output files with the following content:
> > > > > >
> > > > > > file 1: [{"name":"document 1"
> > > > > > file 2: "type":"pdf"}
> > > > > > file 3: {"name":"document 2"
> > > > > > file 4: "type":"pdf"}]
> > > > > >
> > > > > > Am i doing something wrong with my JsonPath? Any help is very much 
> > > > > > appreciated!
> > > > > >
> > > > > > Cheers,
> > > > > >
> > > > > > - Joery
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Claus Ibsen
> > > > > -----------------
> > > > > http://davsclaus.com @davsclaus
> > > > > Camel in Action 2: https://www.manning.com/ibsen2
> > >
> > >
> > >
> > > --
> > > Claus Ibsen
> > > -----------------
> > > http://davsclaus.com @davsclaus
> > > Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to