Skip to content

revinate/assertj-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AssertJ Json

Build Status Maven Central Javadoc codecov.io Codacy Badge

A set of AssertJ assertions to validate JSON.

JsonPath

Use JsonPathAssert to extract values using JsonPath and validate as a Java string, integer or list.

Example:

DocumentContext ctx = JsonPath.parse("{\"value\":\"a text value\"}");

assertThat(ctx).jsonPathAsString("$.value").contains("text").endsWith("value");

Runtime configuration

JsonPathAssert uses JayWay JsonPath under the covers. In order to execute more complex extractions like array of strings to List<String> you need to have Jackson or Gson in your classpath and configure JsonPath to use one of them.

One option is to execute the following snipped of code in a @BeforeClass method in your test class.

Configuration.setDefaults(new Configuration.Defaults() {
    private final JsonProvider jsonProvider = new JacksonJsonProvider();
    private final MappingProvider mappingProvider = new JacksonMappingProvider();

    @Override
    public JsonProvider jsonProvider() {
        return jsonProvider;
    }

    @Override
    public MappingProvider mappingProvider() {
        return mappingProvider;
    }

    @Override
    public Set<Option> options() {
        return EnumSet.noneOf(Option.class);
    }
});

About

A set of AssertJ assertions to validate JSON.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages