Matthew J Greenwood
9 years ago
5 changed files with 60 additions and 1 deletions
@ -0,0 +1,37 @@ |
|||||||
|
package com.jayway.jsonpath.internal.function.text; |
||||||
|
|
||||||
|
import com.jayway.jsonpath.internal.EvaluationContext; |
||||||
|
import com.jayway.jsonpath.internal.PathRef; |
||||||
|
import com.jayway.jsonpath.internal.function.Parameter; |
||||||
|
import com.jayway.jsonpath.internal.function.PathFunction; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* String function concat - simple takes a list of arguments and/or an array and concatenates them together to form a |
||||||
|
* single string |
||||||
|
* |
||||||
|
* Created by mgreenwood on 12/11/15. |
||||||
|
*/ |
||||||
|
public class Concatenate implements PathFunction { |
||||||
|
@Override |
||||||
|
public Object invoke(String currentPath, PathRef parent, Object model, EvaluationContext ctx, List<Parameter> parameters) { |
||||||
|
StringBuffer result = new StringBuffer(); |
||||||
|
if(ctx.configuration().jsonProvider().isArray(model)){ |
||||||
|
Iterable<?> objects = ctx.configuration().jsonProvider().toIterable(model); |
||||||
|
for (Object obj : objects) { |
||||||
|
if (obj instanceof String) { |
||||||
|
result.append(obj.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if (parameters != null) { |
||||||
|
for (Parameter param : parameters) { |
||||||
|
if (param.getCachedValue() != null) { |
||||||
|
result.append(param.getCachedValue().toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
} |
@ -1,7 +1,9 @@ |
|||||||
package com.jayway.jsonpath.internal.function; |
package com.jayway.jsonpath.internal.function.text; |
||||||
|
|
||||||
import com.jayway.jsonpath.internal.EvaluationContext; |
import com.jayway.jsonpath.internal.EvaluationContext; |
||||||
import com.jayway.jsonpath.internal.PathRef; |
import com.jayway.jsonpath.internal.PathRef; |
||||||
|
import com.jayway.jsonpath.internal.function.Parameter; |
||||||
|
import com.jayway.jsonpath.internal.function.PathFunction; |
||||||
|
|
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
Loading…
Reference in new issue