json-hamcrest-matcher

This is a hamcrest matcher for partially matching json objects.

Лицензия

Лицензия

Категории

Категории

JSON Данные
Группа

Группа

com.arusarka
Идентификатор

Идентификатор

json-hamcrest-matcher
Последняя версия

Последняя версия

1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

json-hamcrest-matcher
This is a hamcrest matcher for partially matching json objects.
Система контроля версий

Система контроля версий

https://github.com/arusarka/json-hamcrest-matcher/tree/master

Скачать json-hamcrest-matcher

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.arusarka/json-hamcrest-matcher/ -->
<dependency>
    <groupId>com.arusarka</groupId>
    <artifactId>json-hamcrest-matcher</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.arusarka/json-hamcrest-matcher/
implementation 'com.arusarka:json-hamcrest-matcher:1.0'
// https://jarcasting.com/artifacts/com.arusarka/json-hamcrest-matcher/
implementation ("com.arusarka:json-hamcrest-matcher:1.0")
'com.arusarka:json-hamcrest-matcher:jar:1.0'
<dependency org="com.arusarka" name="json-hamcrest-matcher" rev="1.0">
  <artifact name="json-hamcrest-matcher" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.arusarka', module='json-hamcrest-matcher', version='1.0')
)
libraryDependencies += "com.arusarka" % "json-hamcrest-matcher" % "1.0"
[com.arusarka/json-hamcrest-matcher "1.0"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-databind jar 2.1.5
org.hamcrest : hamcrest-core jar 1.3

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11
org.mockito : mockito-core jar 1.9.5

Модули Проекта

Данный проект не имеет модулей.

Hamcrest Matcher for JSON

This library provides a hamcrest matcher for json. The idea of this matcher is to provide partial matching of json objects. The most important aspect of the matcher is that the relaxed (or partial) matching style works at any level nested inside a json object. What that means is, as long as the expected json is contained inside the actual json, it would match.

Maven dependency

<dependency>
    <groupId>com.arusarka</groupId>
    <artifactId>json-hamcrest-matcher</artifactId>
    <version>1.0</version>
</dependency>

Basic usage

Using with JUnit 4

Assert.assertThat(actual, JSONMatcher.shouldContainJson(expected));

where actual and expected are both json string variables.

Given below are a bunch of different cases for which the matcher will work.

Json object attribute absent in expected

Following jsons would match since the matcher does a partial match.

Actual Expected
{"foo" : "bar","baz" : "qux"} {"foo" : "bar"}

However, the following would not.

Actual Expected
{"foo" : "bar"} {"foo" : "bar","bar" : "qux"}

Json arrays matching

The matcher is very relaxed about array matching. It would match if expected array elements match partially with any element inside actual json array. It does not require that the sizes of expected and actual array to match. Nor does not require the order to be the same.

Following jsons would match.

Actual Expected
[ { "foo": "bar", "bar": "qux" }, { "hello": "world", "lorem": "ipsum" } ] [ { "foo": "bar", "bar": "qux" } ]
[ { "foo": "bar", "bar": "qux" } ] [ { "foo": "bar" } ]

Версии библиотеки

Версия
1.0