-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/1.1.0' into master/1.x
- Loading branch information
Showing
7 changed files
with
122 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
jackson-jq/src/test/java/net/thisptr/jackson/jq/CustomFunctionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.thisptr.jackson.jq; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.IntNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import net.thisptr.jackson.jq.exception.JsonQueryException; | ||
import net.thisptr.jackson.jq.path.Path; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
// end-to-end test of custom function | ||
public class CustomFunctionTest { | ||
|
||
@Test | ||
public void testCustomFunction() throws Exception { | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
Version version = Versions.JQ_1_6; | ||
|
||
Scope rootScope = Scope.newEmptyScope(); | ||
|
||
BuiltinFunctionLoader.getInstance().loadFunctions(version, rootScope); | ||
|
||
rootScope.addFunction("times100", 1, new Function() { | ||
@Override | ||
public void apply(Scope scope, List<Expression> args, JsonNode in, Path path, PathOutput output, Version version) throws JsonQueryException { | ||
args.get(0).apply(scope, in, (numberNode) -> { | ||
assert (numberNode.isIntegralNumber()); | ||
output.emit(new IntNode(numberNode.asInt() * 100), null); | ||
}); | ||
} | ||
}); | ||
|
||
String input = "{ \"a\": 5 }"; | ||
|
||
Scope childScope = Scope.newChildScope(rootScope); | ||
|
||
JsonQuery query = JsonQuery.compile("{ \"a\": times100(.a) }", version); | ||
|
||
final List<JsonNode> out = new ArrayList<>(); | ||
query.apply(childScope, mapper.readTree(input), out::add); | ||
assertThat(out).hasSize(1); | ||
assertThat(out.get(0)).isInstanceOf(ObjectNode.class); | ||
assertThat(out.get(0).toString()).isEqualTo("{\"a\":500}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<groupId>net.thisptr</groupId> | ||
<artifactId>jackson-jq-parent</artifactId> | ||
<packaging>pom</packaging> | ||
<version>1.0.1</version> | ||
<version>1.1.0</version> | ||
<name>${project.groupId}:${project.artifactId}</name> | ||
<description>jq for Jackson JSON Processor</description> | ||
<url>https://github.com/eiiches/jackson-jq</url> | ||
|
@@ -28,7 +28,7 @@ | |
<connection>scm:git:[email protected]:eiiches/jackson-jq.git</connection> | ||
<developerConnection>scm:git:[email protected]:eiiches/jackson-jq.git</developerConnection> | ||
<url>[email protected]:juven/git-demo.git</url> | ||
<tag>1.0.1</tag> | ||
<tag>1.1.0</tag> | ||
</scm> | ||
|
||
<modules> | ||
|