hamcrest-jackson ![All Contributors](https://camo.githubusercontent.com/53f9a656235e69ec7d261f9ee1fc301bc8f717185e15dfa7fcbac37230f65b5f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616c6c5f636f6e7472696275746f72732d332d6f72616e67652e7376673f7374796c653d666c61742d737175617265)
The Hamcrest Jackson library provides a set of matchers for Json node elements.
How to use hamcrest-jackson in your project:
- Clone this project
- Build it using maven clean install
- Add it to your dependencies using
<dependency>
<groupId>nl.fd</groupId>
<artifactId>hamcrest-jackson</artifactId>
<version>1.0.6-SNAPSHOT</version>
</dependency>
Example Usage
Here we provide a code sample to give you a rough idea how easy to use this library is.
JsonNode queryNode = mapper.readTree(someQueryBuilder.toString());
assertThat(queryNode,
hasJsonField("function_score",
hasJsonField("query", isJsonText("apple annual figures")),
hasJsonField("fields",isJsonArray("title", "content"))
)
);
Matchers
The following matchers are provided:
- HasJsonField Matcher for checking if an object has a JSON field.
- hasJsonField
- IsJsonArray Matcher for checking if an object is a JSON array.
- isJsonArray
- IsJsonBoolean Matcher for checking if an object is a JSON boolean.
- isJsonBoolean
- IsJsonInt Matcher for checking if an object is a JSON integer.
- isJsonInt
- IsJsonText Matcher for checking if an object is a JSON integer.
- isJsonText
Contributors
โจ
Thanks goes to these wonderful people (emoji key):
Joram Hannema |
Jeroen M Snoeij |
Quinten Krijger |
This project follows the all-contributors specification. Contributions of any kind welcome!