@Override protected void map(final IJsonNode value, JsonCollector<IJsonNode> out) { final IJsonNode target = this.arrayPath.evaluate(value); if (!(target instanceof IArrayNode<?>)) throw new EvaluationException("Cannot split non-array"); final IArrayNode<?> array = (IArrayNode<?>) target; int index = 0; IntNode indexNode = IntNode.valueOf(0); IArrayNode<IJsonNode> contextNode = JsonUtil.asArray(NullNode.getInstance(), indexNode, array, value); for (IJsonNode element : array) { contextNode.set(0, element); indexNode.setValue(index); out.collect(this.splitProjection.evaluate(contextNode)); index++; } }
/** * Reuses a {@link IJsonNode} by simply copying the value from the source to the target node. The * value will not be copied if the source and target are no {@link IPrimitiveNode}s * * @param source the IJsonNode that should be used as the source * @param target the IJsonNode that should be used as the target * @return the reused IJsonNode */ public static IJsonNode reusePrimitive(final IJsonNode source, final IJsonNode target) { final Class<? extends IJsonNode> sourceClass = source.getClass(); if (sourceClass != target.getClass() || sourceClass.equals(BooleanNode.class) || source.isNull()) return source; if (!(source instanceof IPrimitiveNode)) return source; if (sourceClass.equals(IntNode.class)) ((IntNode) target).setValue(((IntNode) source).getIntValue()); else if (sourceClass.equals(DoubleNode.class)) ((DoubleNode) target).setValue(((DoubleNode) source).getDoubleValue()); else if (sourceClass.equals(LongNode.class)) ((LongNode) target).setValue(((LongNode) source).getLongValue()); else if (sourceClass.equals(DecimalNode.class)) ((DecimalNode) target).setValue(((DecimalNode) source).getDecimalValue()); else if (sourceClass.equals(BigIntegerNode.class)) ((BigIntegerNode) target).setValue(((BigIntegerNode) source).getBigIntegerValue()); return target; }