revinate / assertj-json

A set of AssertJ assertions to validate JSON.
MIT License
26 stars 6 forks source link

Accept string as input #7

Open hexwit opened 7 years ago

hexwit commented 7 years ago

it would be very convenient to accept string along with DocumentContext, and do the parsing under the hood. In most cases that saves some space that is pretty important in tests, as there a lot of assertions.

jrglee commented 7 years ago

This idea was considered early. But there are a couple of reasons why this design was not implemented

  1. Just like I mentioned in my comment in #6 AssertJ uses overloads of assertThat and allows the type to dictate the assertion strategy. The goal here is to preserve the assertThat(something).customCheck() template. One idea would be to implement a AbstractCharSequenceAssert with a .asJsonDocumentContext() to enable JSON path checks. The downside is you will have to extend org.assertj.core.api.Assertions to replace the default string assertion with the custom assertion.
  2. This library was build on top of JsonPath which a highly configurable library. By doing the conversion under the covers this library will have to assume some default configs and allow configuration points. This kind of change would increase the complexity since it would introduce a lot of coupling with JsonPath.

I think the best solution here is to create your own wrapper like I described in item 1. With that you can write your own abstraction, and make the assertions a lot simpler for your application. There is a balance between integrating multiple libraries together for an app where you can lock down every version, and for a general use utility where you want to keep it simple so more people can use it. I would like to not put effort in glue code because that would introduce integration issues with a lot other libraries and that defeats the purpose of this simple codebase.