You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of providing a list of properties, can I refer to a member of the class that's a callable function, which will return a the value to use for comparisons?
The text was updated successfully, but these errors were encountered:
Interesting...what use cases did you have in mind? Instance functions, extension functions?
By using callable you lose the ability to enforce that the callable's are actually compatible with the object's being compared (there's no receiver in the type signature like with KProperty), so you run the risk of getting IllegalArgumentException: object is not an instance of declaring class.
I have a bunch of POKOs that have Hibernate annotations, and matching "mixin" classes that are used to serialize the POKOs with Jackson. An oversimplified example might look like this:
@Entity
class Foo {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "id", updatable = false, nullable = false)
@JsonIgnore
var id: UUID? = null
@Column(name = "name")
var name: String? = null
fun getTransformedName(): String? {
return name?.capitalize()
}
}
@JsonPropertyOrder("name", "transformedName")
class FooMixin {
@JsonProperty("transformedName", access = JsonProperty.Access.READ_ONLY)
abstract fun getTransformedName(): String?
}
Let's say I need to compare two Foo entities for functional equality. That means I want to skip the id field, but I want to compare the name field, and also what is essentially a transformed name field.
Instead of providing a list of properties, can I refer to a member of the class that's a callable function, which will return a the value to use for comparisons?
The text was updated successfully, but these errors were encountered: