Coder Social home page Coder Social logo

ekino / jcv Goto Github PK

View Code? Open in Web Editor NEW
21.0 22.0 0.0 388 KB

JSON Content Validator (JCV) allows you to compare JSON contents with embedded validation.

Home Page: https://ekino.github.io/jcv

License: MIT License

Kotlin 87.39% Java 11.76% Shell 0.20% HTML 0.64%
java json testing assertions assertj-assertions assertj hamcrest hamcrest-matchers wiremock wiremock-mappings

jcv's Issues

Make jsonMatcher strict by default

Hello,
I was wondering if it would be nicer to have the usually used jsonMatcher() method strict by default (.mode(JSONCompareMode.STRICT)). Moreover we could add another method like unorderedJsonMatcher() to perform assertions when the order can change.

This would be somehow like what we have in assertj.

What do you think about that ?

Strict typing in comparators may produce a ClassCastException

A JsonValueComparator uses the same type for the actual and expected parameters. This may be problematic when the actual type is not the same as the expected type.

Here's an example:

Actual is

{
 "date": null
}

Expected is

{
 "date": "{#date_time_format:iso_instant#}"
}

A ClassCastException will be thrown because "date" will be "deserialized" as a null JSONObject, and DateTimeFormatComparator expects an actual of type String.

Provide a changelog

Hi,

Could you please provide a changelog listing the changes between two releases ? It would help this library consumers a lot.

Thanks :)

Add wiremock module

Hi,

it could be cool to provide a wiremock module to validate request or response body json with JCV validators.

In wiremock, when we try to compare a json array with another one but not in the same order, the EqualToJsonPattern doesn't match. ( here is an issue in wiremock repository : wiremock/wiremock#1230 ). If we use a JCV with wiremock it should fix this.

If you want to test the current EqualToJsonPattern error, here is a test :

@Test
  void reproduceFailingIgnoreArrayOrder() {
    var expected = "{ \"array\": [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\"] }";
    var actual = "{ \"array\": [\"b\",\"a\",\"d\",\"c\",\"e\",\"f\",\"g\",\"h\"] }";
    var pattern = new EqualToJsonPattern(expected, true, false);
    var result = pattern.match(actual);
    var exact = result.isExactMatch();
    assertTrue(exact);
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.