Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ NOTE: Jackson 3.x components rely on 2.x annotations; there are no separate
=== Releases ===
------------------------------------------------------------------------

- Use `Objects.equals()` for comparison (with Java 8 baseline)

2.20-rc1 (04-Aug-2025)

#293: Improve duplicate Id with different associated object error message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Objects;

/**
* Jackson-specific annotation used for indicating that value of
Expand Down Expand Up @@ -226,12 +227,9 @@ public boolean equals(Object o) {
if (o.getClass() == getClass()) {
Value other = (Value) o;

return (_id == null && other._id == null
|| _id != null && _id.equals(other._id))
&& (_useInput == null && other._useInput == null
|| _useInput != null && _useInput.equals(other._useInput))
&& (_optional == null && other._optional == null
|| _optional != null && _optional.equals(other._optional));
return Objects.equals(_id, other._id)
&& Objects.equals(_useInput, other._useInput)
&& Objects.equals(_optional, other._optional);
}
return false;
}
Expand All @@ -243,7 +241,7 @@ public boolean equals(Object o) {
*/

private static boolean _empty(Object id, Boolean useInput, Boolean optional) {
return (id == null) && (useInput == null) && optional == null;
return (id == null) && (useInput == null) && (optional == null);
}
}
}
22 changes: 6 additions & 16 deletions src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.annotation.*;
import java.util.Locale;
import java.util.Objects;
import java.util.TimeZone;

/**
Expand Down Expand Up @@ -900,22 +901,11 @@ public boolean equals(Object o) {
|| !_features.equals(other._features)) {
return false;
}
return _equal(_lenient, other._lenient)
&& _equal(_timezoneStr, other._timezoneStr)
&& _equal(_pattern, other._pattern)
&& _equal(_timezone, other._timezone)
&& _equal(_locale, other._locale);
}

private static <T> boolean _equal(T value1, T value2)
{
if (value1 == null) {
return (value2 == null);
}
if (value2 == null) {
return false;
}
return value1.equals(value2);
return Objects.equals(_lenient, other._lenient)
&& Objects.equals(_timezoneStr, other._timezoneStr)
&& Objects.equals(_pattern, other._pattern)
&& Objects.equals(_timezone, other._timezone)
&& Objects.equals(_locale, other._locale);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,8 @@ public int hashCode() {
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
return (o.getClass() == getClass()) && _equals(_included, ((Value) o)._included);
}

private static boolean _equals(Set<String> a, Set<String> b)
{
return a == null ? (b == null)
// keep this last just because it can be expensive
: a.equals(b);
return (o.getClass() == getClass())
&& Objects.equals(_included, ((Value) o)._included);
}

private static Set<String> _asSet(String[] v)
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/com/fasterxml/jackson/annotation/JsonTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Objects;

/**
* Annotation used for configuring details of if and how type information is
Expand Down Expand Up @@ -536,20 +537,9 @@ private static boolean _equals(Value a, Value b)
&& (a._inclusionType == b._inclusionType)
&& (a._defaultImpl == b._defaultImpl)
&& (a._idVisible == b._idVisible)
&& _equal(a._propertyName, b._propertyName)
&& _equal(a._requireTypeIdForSubtypes, b._requireTypeIdForSubtypes)
&& Objects.equals(a._propertyName, b._propertyName)
&& Objects.equals(a._requireTypeIdForSubtypes, b._requireTypeIdForSubtypes)
;
}

private static <T> boolean _equal(T value1, T value2)
{
if (value1 == null) {
return (value2 == null);
}
if (value2 == null) {
return false;
}
return value1.equals(value2);
}
}
}