robfletcher / strikt

An assertion library for Kotlin
https://strikt.io/
Apache License 2.0
549 stars 59 forks source link

Not very useful output when comparing Jackson JsonNode objects #264

Open cloudshiftchris opened 2 years ago

cloudshiftchris commented 2 years ago

Comparing Jackson JsonNode objects is useful more matching up JSON, sidestepping formatting and key-order considerations.

When doing expectThat(actualNode).isEqualTo(expectedNode) the comparison works as expected, however the failure output (when the nodes do not match) doesn't properly show the toString() of the nodes.

▼ Expect that [CdkResource(name=SecureBucket1ED1C5CE, type=AWS::S3::Bucket)]:
  ✓ has only one element
  ▼ single element CdkResource(name=SecureBucket1ED1C5CE, type=AWS::S3::Bucket):
    ▼ [[[], [[[[[[]]]]], [[], [], [], []]], [], []]]:
      ✗ is equal to [[[], [[[[[[]]]]], [[], [], [], []]], [], []]] (ObjectNode)
              found [[[], [[[[[[]]]]], [[], [], [], []]], [], []]] (ObjectNode)

Suspect this is related to the formatValue() method, given that JsonNode implements Iterable.

Expected behaviour: show the toString() output of the JsonNode objects

strikt 0.34.1. Issue occurs with or without strikt-jackson module.

incrop commented 1 year ago

There was a similar issue: https://github.com/robfletcher/strikt/issues/75 Looks like it was fixed (https://github.com/robfletcher/strikt/pull/80), but then jackson team removed toString() from ObjectNode, and preferToString() does not help anymore: https://github.com/FasterXML/jackson-databind/commit/8ec1e5ecfc07ad893bd4e8d151d9176795f4dc41