I have a class
public class A
{
@Nonnull
private final String m_a;
@CheckForNull
private final B m_b;
@Nonnull
private final List<C> m_c;
@JsonCreator
public A(
@JsonProperty("a") @Nonnull final String a,
@JsonProperty("b") @CheckForNull final B b,
@JsonProperty("c") @Nonnull final List<C> c
)
{
m_a = a;
m_b = b;
m_c = checkNotNull(c);
}
// getters ...
}
How would you recommend to compare if two A instances are equal?
I can use Jackson to serialize the JSON to a String (.writeValueAsString
) and compare, but that is not cheap. Is it better if I override equals
and hashcode
and compare every field instead? What does it look like then?