Skip to content

Differences in excluded fields in objects of a collection cause state of collection diff to be changed #216

Open
@luispollo

Description

@luispollo

Hi Daniel,

First of all, thanks a lot for the awesome library! We've been using it in open-source Spinnaker for over a year now with great results.

I think I may have run into a corner case. We are configuring a differ in Kotlin like so:

    val differ: ObjectDiffer = ObjectDifferBuilder
      .startBuilding()
      .apply {
        comparison().ofType(Instant::class.java).toUseEqualsMethod()
        inclusion().resolveUsing(object : InclusionResolver {
          override fun getInclusion(node: DiffNode): Inclusion =
            if (node.getPropertyAnnotation<ExcludedFromDiff>() != null) EXCLUDED else INCLUDED

          override fun enablesStrictIncludeMode() = false
        })
      }
      .build()

This allows us to use a @ExcludedFromDiff annotation to exclude unwanted properties from the diff. This normally works just fine, but I came across a case where, if the objects with excluded fields are part of a collection, and I compare the collection itself, the differ reports a state of CHANGED instead of the expected UNTOUCHED.

For example, this comparison reports UNTOUCHED:

data class MyObject(
  @get:ExcludedFromDiff
  val prop: String
)

val base = MyObject("test")
differ.compare(base, base.copy(prop = "whatever"))

But this comparison reports CHANGED:

differ.compare(setOf(base), setOf(base.copy(prop = "whatever")))

I've tried my best to debug the issue, but failed. If you have any insights and could at least confirm whether you think this might be a bug and whether there's any workaround in version 0.95, that would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions