diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/ResultPathMerge.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/ResultPathMerge.java
index ded0095a87..56f054cb11 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/ResultPathMerge.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/ResultPathMerge.java
@@ -2,16 +2,26 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Applies a state's JSONPath {@code ResultPath}, merging the state result into the effective input.
* Extracted from {@link AslExecutor} so the merge rules (including the AWS
* {@code States.ResultPathMatchFailure} case) are unit-testable without the Vert.x-bound executor.
*
- *
AWS: {@code ResultPath} names where the result is inserted into the state's raw input. When the
- * input is not a JSON object but {@code ResultPath} addresses an object member (a {@code $.field} path),
- * the path cannot apply and the interpreter fails with {@code States.ResultPathMatchFailure}. It does
+ *
AWS: {@code ResultPath} names where the result is inserted into the state's raw input. A
+ * {@code ResultPath} is a Reference Path, and a dotted field ({@code $.a}), a bracket index
+ * ({@code $[1]}, {@code $.a[0].b}, {@code $[0][1]}), and a single-quoted bracket field name
+ * ({@code $.abc.['def ghi']}, AWS's documented form for a field name a dotted segment cannot carry)
+ * are all legal segments; the ASL spec excludes only the {@code @}, {@code ..}, {@code ,},
+ * {@code :}, and {@code ?} operators from a reference path, not {@code [n]} or a quoted field name.
+ * When the input shape does not match the path, for example a {@code $.field}
+ * path against a non-object input, or a {@code [n]} index that an existing array does not have, the
+ * path cannot apply and the interpreter fails with {@code States.ResultPathMatchFailure}. It does
* NOT silently discard the input.
*
* @see ASL ResultPath
@@ -32,17 +42,21 @@ public final class ResultPathMerge {
* Merge {@code result} into {@code input} at {@code resultPath}.
*
*
{@code "$"} replaces {@code input} with {@code result}
+ *
a leading field segment ({@code $.a}) against a non-object input, or a leading index
+ * segment ({@code $[n]}) against a non-array input, raises {@link ResultPathMatchException}
+ *
an index segment addressing a position an existing array does not have (missing array,
+ * wrong type, or out of bounds) raises {@link ResultPathMatchException} rather than
+ * fabricating array elements
+ *
otherwise a deep copy of {@code input} is returned with {@code result} set at the path,
+ * creating missing intermediate objects along dotted segments the way {@code $.a.b} always has
*
*
- *
Known residuals (unchanged, pre-existing {@link #setPath} limitations): a {@code $[...]}-style
- * ResultPath is not applied (returns the result for a non-object input, and is a no-op merge for an
- * object input), and a {@code $.a.b} path whose {@code $.a} is a scalar is silently overwritten rather
- * than raising {@code States.ResultPathMatchFailure}.
+ *
Known residual (unchanged, pre-existing behavior): a {@code $.a.b} path whose {@code $.a} is
+ * a scalar is silently overwritten with a new object rather than raising
+ * {@code States.ResultPathMatchFailure}; the same applies to a bracket-addressed element that is
+ * a scalar where the path expects an object or array.
*/
public static JsonNode merge(JsonNode input, String resultPath, JsonNode result, ObjectMapper mapper) {
if (resultPath == null || resultPath.equals("null")) {
@@ -51,37 +65,148 @@ public final class ResultPathMerge {
if ("$".equals(resultPath)) {
return result;
}
- if (!input.isObject()) {
- if (resultPath.startsWith("$.")) {
- throw new ResultPathMatchException(
- "Failed to apply ResultPath '" + resultPath + "': the state input is not a JSON object");
- }
- return result; // non-$. paths ($[...]) are a documented residual: unchanged behavior
+ List