So what happens when the field is null?

Are you saying that you want Camel to discard adding the "source"
property if the evaluated value is null?
That is likely not support as the method is called setProperty which
indicates the property is set.

We could consider adding support for ? so you can say

setProperty("?source", xxx)

and then its only set if the value is not null/empty.

However how often is there such a use-case in the community?





On Wed, May 10, 2017 at 1:51 PM, Mic <zerocoo...@web.de> wrote:
> Hi guys,
>
> i struggle with the following case. I have a "body" with some fields like
> "title", "source" etc..
>
> Now i would like to set a Property with the value in field "source". The
> problem is, the field is optional, so it is not present always.
>
> It works if it is present with
> ".setProperty("source").groovy("request.body.source")" but crash if field
> "source" is not available .. But how can i enrich this part with the option
> that "source" is not available. I tried null safe groovy syntax,
> choice()/when() route and so on..
>
> Can you please tell me the correct syntax to check if "request.body.source"
> is available, if true, setProperty with the value.. if not present, ignore..
>
> Thanks a lot for your help.
> Best Regards
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Problem-using-setProperty-with-groovy-on-optional-Field-tp5799222.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to