jamesnetherton commented on code in PR #30376:
URL: https://github.com/apache/camel/pull/30376#discussion_r4627092048
##########
components/camel-jq/src/main/java/org/apache/camel/language/jq/JqExpression.java:
##########
@@ -195,19 +196,26 @@ public Object evaluate(Exchange exchange) {
* @return the {@link JsonNode} to be processed by the expression
*/
private JsonNode getPayload(Exchange exchange) throws Exception {
- JsonNode payload = source.evaluate(exchange, JsonNode.class);
+ Object value = source.evaluate(exchange, Object.class);
+ // Jackson 3 cannot convert a Jackson 2 node; the text of a node of
either line is its JSON
+ JsonNode payload = typeConverter.convertTo(JsonNode.class, exchange,
Review Comment:
A `MissingNode` is now read as `null`, as jackson-jq 1 did.
`JqExpressionTest.emptyBodyIsReadAsNull` covers `type`, `try .a catch "c"` and
`. // "def"` for `""`, `" "` and `"\n"`.
_Claude Code on behalf of jamesnetherton_
##########
components/camel-jq/src/main/java/org/apache/camel/language/jq/JqExpression.java:
##########
@@ -195,19 +196,26 @@ public Object evaluate(Exchange exchange) {
* @return the {@link JsonNode} to be processed by the expression
*/
private JsonNode getPayload(Exchange exchange) throws Exception {
- JsonNode payload = source.evaluate(exchange, JsonNode.class);
+ Object value = source.evaluate(exchange, Object.class);
+ // Jackson 3 cannot convert a Jackson 2 node; the text of a node of
either line is its JSON
+ JsonNode payload = typeConverter.convertTo(JsonNode.class, exchange,
+ isJackson2Node(value) ? value.toString() : value);
// if body is stream cached then reset, so we can re-read it again
MessageHelper.resetStreamCache(exchange.getMessage());
if (payload == null) {
// tell apart a source that is null from one that is set but holds
no JSON
- if (source.evaluate(exchange, Object.class) == null) {
+ if (value == null) {
throw new InvalidPayloadException(exchange, JsonNode.class,
exchange.getIn(), nullSourceHint(exchange));
}
throw new InvalidPayloadException(exchange, JsonNode.class);
}
return payload;
}
+ private static boolean isJackson2Node(Object value) {
Review Comment:
The result now goes through its JSON text when the result type is a Jackson
2 type, as the input does
(`JqExpressionTest.jackson2NodeResultTypeIsConvertedFromJson`). The upgrade
guide notes that it needs `camel-jackson`.
_Claude Code on behalf of jamesnetherton_
##########
components/camel-jq/pom.xml:
##########
@@ -43,16 +43,41 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-jackson</artifactId>
+ <artifactId>camel-jackson3</artifactId>
Review Comment:
Yes, that is intended with the Jackson 3 migration. The camel-jq section of
the upgrade guide now says that camel-jq brings `camel-jackson3`, that
`marshal().json()` then uses the Jackson 3 data format with the Jackson 3
defaults, that the `camel.dataformat.jackson.*` options of
`camel-jackson-starter` no longer apply, and how to keep the Jackson 2 data
format.
_Claude Code on behalf of jamesnetherton_
##########
components/camel-jq/src/main/docs/jq-language.adoc:
##########
@@ -22,8 +22,8 @@ include::partial$language-options.adoc[]
=== Message body types
-Camel JQ leverages `camel-jackson` for type conversion.
-To enable camel-jackson POJO type conversion, refer to the Camel Jackson
documentation.
+Camel JQ leverages `camel-jackson3` (Jackson 3) for type conversion.
Review Comment:
Added a sentence to the jq page and to the upgrade guide.
_Claude Code on behalf of jamesnetherton_
##########
components/camel-jq/src/main/java/org/apache/camel/language/jq/JqFunctions.java:
##########
@@ -19,106 +19,172 @@
import java.util.List;
import java.util.Map;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.NullNode;
-import com.fasterxml.jackson.databind.node.TextNode;
-import net.thisptr.jackson.jq.BuiltinFunctionLoader;
-import net.thisptr.jackson.jq.Expression;
-import net.thisptr.jackson.jq.Function;
-import net.thisptr.jackson.jq.PathOutput;
-import net.thisptr.jackson.jq.Scope;
-import net.thisptr.jackson.jq.Version;
-import net.thisptr.jackson.jq.Versions;
-import net.thisptr.jackson.jq.exception.JsonQueryException;
-import net.thisptr.jackson.jq.internal.tree.FunctionCall;
-import net.thisptr.jackson.jq.path.Path;
+import net.thisptr.jackson.jq.v2.core.EnvironmentBuilder;
+import net.thisptr.jackson.jq.v2.core.version.Versions;
+import net.thisptr.jackson.jq.v2.json.JsonNodeType;
+import net.thisptr.jackson.jq.v2.json.JsonProvider;
+import net.thisptr.jackson.jq.v2.json.impl.jackson3.Jackson3JsonProvider;
+import net.thisptr.jackson.jq.v2.spi.BindContext;
+import net.thisptr.jackson.jq.v2.spi.Expression;
+import net.thisptr.jackson.jq.v2.spi.Function;
+import net.thisptr.jackson.jq.v2.spi.FunctionSignature;
+import net.thisptr.jackson.jq.v2.spi.Output;
+import net.thisptr.jackson.jq.v2.spi.RuntimeContext;
+import net.thisptr.jackson.jq.v2.spi.annotations.FunctionRegistration;
+import net.thisptr.jackson.jq.v2.spi.exception.JsonQueryException;
+import net.thisptr.jackson.jq.v2.spi.path.Path;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.StreamCache;
import org.apache.camel.util.concurrent.ContextValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import tools.jackson.databind.JsonNode;
+
+/**
+ * The Camel supplied jq functions.
+ * <p/>
+ * A new function must be annotated with {@link FunctionRegistration}, listed
in
+ * {@code META-INF/services/net.thisptr.jackson.jq.v2.spi.Function} and added
to {@link #CAMEL_FUNCTIONS}. The
+ * {@code ServiceLoader} lookup brings the functions to an environment that
Camel does not build, such as one from a CDI
+ * producer, as a built environment cannot be changed. There a function of the
same signature in another jar may win, as
+ * jackson-jq resolves such a clash in classpath order.
+ */
public final class JqFunctions {
public static final ContextValue<Exchange> EXCHANGE_LOCAL =
ContextValue.newThreadLocal("JqExchange");
private static final Logger LOGGER =
LoggerFactory.getLogger(JqFunctions.class);
+ private static final Map<FunctionSignature, Function> CAMEL_FUNCTIONS =
Map.of(
+ FunctionSignature.of(Header.NAME, 1), new Header(),
+ FunctionSignature.of(Header.NAME, 2), new Header(),
+ FunctionSignature.of(Property.NAME, 1), new Property(),
+ FunctionSignature.of(Property.NAME, 2), new Property(),
+ FunctionSignature.of(Constant.NAME, 1), new Constant(),
+ FunctionSignature.of(Constant.NAME, 2), new Constant(),
+ FunctionSignature.of(Variable.NAME, 1), new Variable(),
+ FunctionSignature.of(Variable.NAME, 2), new Variable(),
+ FunctionSignature.of(Body.NAME, 0), new Body());
Review Comment:
Switched to `Map.ofEntries`.
_Claude Code on behalf of jamesnetherton_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]