4

My spring integration is trying to transform JSON message from input channel and extract a value from JSON message by providing the corresponding key. Its throwing SpelEvaluationException.

Spring Integration Configuration

<int:object-to-json-transformer input-channel="inputEventChannel" output-channel="jsonMapChannel"/>

<int:transformer input-channel="jsonMapChannel" output-channel="transformChannel" 
     expression="#jsonPath(payload, '$.[0].EVENTNAME')"/>

Error Message

Caused by: org.springframework.messaging.MessageHandlingException: Expression evaluation failed: #jsonPath(payload, '$.[0].EVENTNAME'); nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1022E: The function 'jsonPath' mapped to an object of type 'class org.springframework.expression.TypedValue' which cannot be invoked, failedMessage=GenericMessage [payload=[{"EVENTID":5064015,"EVENTNAME":"Account","EVENTID":"15590","APPLICATIONID":1,"CREATEDTIMESTAMP":1493929367000,"TRANSACTIONID":"100.2.33"}], headers={json__ContentTypeId__=class org.springframework.util.LinkedCaseInsensitiveMap, id=acbc053a-b466-fbb9-8d3d-f60c78371b3e, json__TypeId__=class java.util.ArrayList, contentType=application/json, timestamp=1493933245720}]

May I know what went wrong here? I even tried with this too. Same error behavior.

#jsonPath(payload, '$.EVENTNAME')

Thanks.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
VeeAar
  • 91
  • 1
  • 12

1 Answers1

3

EL1022E means that the jsonPath function is not registered as a function.

Which means the JsonPath jar is not on the classpath.

DEBUG logging should show this log...

logger.debug("The '#jsonPath' SpEL function cannot be registered: " +
        "there is no jayway json-path.jar on the classpath.");
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks @GaryRussell It worked after I added the maven entry for json-path as you suggested. – VeeAar May 05 '17 at 18:57
  • Have one more question on handling JSON message in Spring Integration. If we need to modify some key-value pairs or adding few more key-value pairs to the existing JSON message, may I know how to achieve those? Thanks. – VeeAar May 05 '17 at 20:53
  • You should really ask a new question - the admins here don't like extended commentary or unrelated questions in comments. You can use a json-to-object-transformer with the target class being a `LinkedHashMap` - add the new properties and transform it back to json again. That said, it looks like your original object was a list of `LinkedCaseInsensitiveMap` in the first place, so why not manipulate the map before converting to JSON. – Gary Russell May 05 '17 at 21:01
  • Thanks @GaryRussell for your inputs. Going forward, I will post a new question. – VeeAar May 05 '17 at 21:19