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
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static IgnoredPropertyException from(JsonParser p,
Collection<Object> propertyIds)
{
Class<?> ref;
if (fromObjectOrClass instanceof Class<?>) {
ref = (Class<?>) fromObjectOrClass;
if (fromObjectOrClass instanceof Class<?> class1) {
ref = class1;
} else { // also acts as null check:
ref = fromObjectOrClass.getClass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static UnrecognizedPropertyException from(JsonParser p,
Collection<Object> propertyIds)
{
Class<?> ref;
if (fromObjectOrClass instanceof Class<?>) {
ref = (Class<?>) fromObjectOrClass;
if (fromObjectOrClass instanceof Class<?> class1) {
ref = class1;
} else {
ref = fromObjectOrClass.getClass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public ValueInstantiator modifyValueInstantiator(DeserializationConfig config,
// So... in practice it really should always work, in the end. :)
if (ZoneId.class.isAssignableFrom(raw)) {
// let's assume we should be getting "empty" StdValueInstantiator here:
if (defaultInstantiator instanceof StdValueInstantiator) {
StdValueInstantiator inst = (StdValueInstantiator) defaultInstantiator;
if (defaultInstantiator instanceof StdValueInstantiator inst) {
// one further complication: we need ZoneId info, not sub-class
AnnotatedClass ac;
if (raw == ZoneId.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ public Object handleUnexpectedToken(Class<?> instClass, JsonToken t,
protected DateTimeException _peelDTE(DateTimeException e) {
while (true) {
Throwable t = e.getCause();
if (t != null && t instanceof DateTimeException) {
e = (DateTimeException) t;
if (t != null && t instanceof DateTimeException dte) {
e = dte;
continue;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ protected boolean _isExplicitClassOrOb(Object maybeCls, Class<?> implicit) {
if ((maybeCls == null) || (maybeCls == implicit)) {
return false;
}
if (maybeCls instanceof Class<?>) {
return !ClassUtil.isBogusClass((Class<?>) maybeCls);
if (maybeCls instanceof Class<?> class1) {
return !ClassUtil.isBogusClass(class1);
}
return true;
}
Expand All @@ -734,7 +734,7 @@ protected Object _explicitClassOrOb(Object maybeCls, Class<?> implicit) {
if ((maybeCls == null) || (maybeCls == implicit)) {
return null;
}
if ((maybeCls instanceof Class<?>) && ClassUtil.isBogusClass((Class<?>) maybeCls)) {
if (maybeCls instanceof Class<?> class1 && ClassUtil.isBogusClass(class1)) {
return null;
}
return maybeCls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static EnumNamingStrategy createEnumNamingStrategyInstance(Object namingD
if (namingDef == null) {
return defaultNamingStrategy;
}
if (namingDef instanceof EnumNamingStrategy) {
return (EnumNamingStrategy) namingDef;
if (namingDef instanceof EnumNamingStrategy strategy) {
return strategy;
}
if (!(namingDef instanceof Class)) {
throw new IllegalArgumentException(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config,
// to map it to "PROPERTY" instead of "EXTERNAL_PROPERTY"
if (ann instanceof AnnotatedClass) {
JsonTypeInfo.As inclusion = typeInfo.getInclusionType();
if (inclusion == JsonTypeInfo.As.EXTERNAL_PROPERTY && (ann instanceof AnnotatedClass)) {
if (inclusion == JsonTypeInfo.As.EXTERNAL_PROPERTY) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same instanceof checked 2 lines earlier

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

typeInfo = typeInfo.withInclusionType(JsonTypeInfo.As.PROPERTY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public JavaType typeFromId(DatabindContext ctxt, String id) throws JacksonExcept
protected JavaType _typeFromId(DatabindContext ctxt, String id) throws JacksonException
{
DeserializationContext deserializationContext = null;
if (ctxt instanceof DeserializationContext) {
deserializationContext = (DeserializationContext) ctxt;
if (ctxt instanceof DeserializationContext dContext) {
deserializationContext = dContext;
}
if ((_allowedSubtypes != null) && (deserializationContext != null)
&& deserializationContext.isEnabled(
Expand Down Expand Up @@ -108,12 +108,12 @@ protected String _idFrom(DatabindContext ctxt, Object value, Class<?> cls)
// Enum sets and maps are problematic since we MUST know type of
// contained enums, to be able to deserialize.
// In addition, EnumSet is not a concrete type either
if (value instanceof EnumSet<?>) { // Regular- and JumboEnumSet...
Class<?> enumClass = ClassUtil.findEnumType((EnumSet<?>) value);
if (value instanceof EnumSet<?> enumSet) { // Regular- and JumboEnumSet...
Class<?> enumClass = ClassUtil.findEnumType(enumSet);
// not optimal: but EnumSet is not a customizable type so this is sort of ok
str = ctxt.getTypeFactory().constructCollectionType(EnumSet.class, enumClass).toCanonical();
} else if (value instanceof EnumMap<?,?>) {
Class<?> enumClass = ClassUtil.findEnumType((EnumMap<?,?>) value);
} else if (value instanceof EnumMap<?,?> enumMap) {
Class<?> enumClass = ClassUtil.findEnumType(enumMap);
Class<?> valueClass = Object.class;
// not optimal: but EnumMap is not a customizable type so this is sort of ok
str = ctxt.getTypeFactory().constructMapType(EnumMap.class, enumClass, valueClass).toCanonical();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected Object _deserializeWithNativeTypeId(JsonParser p, DeserializationConte
"No (native) type id found when one was expected for polymorphic type handling");
}
} else {
String typeIdStr = (typeId instanceof String) ? (String) typeId : String.valueOf(typeId);
String typeIdStr = (typeId instanceof String string) ? string : String.valueOf(typeId);
deser = _findDeserializer(ctxt, typeIdStr);
}
return deser.deserialize(p, ctxt);
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/tools/jackson/databind/node/ArrayNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ protected ObjectNode _withObject(JsonPointer origPtr,
}
JsonNode n = _at(currentPtr);
// If there's a path, follow it
if ((n != null) && (n instanceof BaseJsonNode)) {
ObjectNode found = ((BaseJsonNode) n)._withObject(origPtr, currentPtr.tail(),
if (n instanceof BaseJsonNode baseNode) {
ObjectNode found = baseNode._withObject(origPtr, currentPtr.tail(),
overwriteMode, preferIndex);
if (found != null) {
return found;
Expand All @@ -116,8 +116,8 @@ protected ArrayNode _withArray(JsonPointer origPtr,
}
JsonNode n = _at(currentPtr);
// If there's a path, follow it
if ((n != null) && (n instanceof BaseJsonNode)) {
ArrayNode found = ((BaseJsonNode) n)._withArray(origPtr, currentPtr.tail(),
if (n instanceof BaseJsonNode baseNode) {
ArrayNode found = baseNode._withArray(origPtr, currentPtr.tail(),
overwriteMode, preferIndex);
if (found != null) {
return found;
Expand Down Expand Up @@ -296,22 +296,21 @@ public Collection<JsonNode> elements() {
@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
if (!(o instanceof ArrayNode)) {
return false;
}
ArrayNode other = (ArrayNode) o;
final int len = _children.size();
if (other.size() != len) {
return false;
}
List<JsonNode> l1 = _children;
List<JsonNode> l2 = other._children;
for (int i = 0; i < len; ++i) {
if (!l1.get(i).equals(comparator, l2.get(i))) {
if (o instanceof ArrayNode other) {
final int len = _children.size();
if (other.size() != len) {
return false;
}
List<JsonNode> l1 = _children;
List<JsonNode> l2 = other._children;
for (int i = 0; i < len; ++i) {
if (!l1.get(i).equals(comparator, l2.get(i))) {
return false;
}
}
return true;
}
return true;
return false;
}

/*
Expand Down Expand Up @@ -1163,8 +1162,8 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof ArrayNode) {
return _children.equals(((ArrayNode) o)._children);
if (o instanceof ArrayNode arrayNode) {
return _children.equals(arrayNode._children);
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/tools/jackson/databind/node/BaseJsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ public ObjectNode withObject(JsonPointer ptr,
{
// Degenerate case of using with "empty" path; ok if ObjectNode
if (ptr.matches()) {
if (this instanceof ObjectNode) {
return (ObjectNode) this;
if (this instanceof ObjectNode objectNode) {
return objectNode;
}
_reportWrongNodeType("Can only call `withObject()` with empty JSON Pointer on `ObjectNode`, not %s",
ClassUtil.nameOf(getClass()));
Expand Down Expand Up @@ -551,8 +551,8 @@ public ArrayNode withArray(JsonPointer ptr,
{
// Degenerate case of using with "empty" path; ok if ArrayNode
if (ptr.matches()) {
if (this instanceof ArrayNode) {
return (ArrayNode) this;
if (this instanceof ArrayNode arrayNode) {
return arrayNode;
}
_reportWrongNodeType("Can only call `withArray()` with empty JSON Pointer on `ArrayNode`, not %s",
ClassUtil.nameOf(getClass()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,7 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof BigIntegerNode) {
BigIntegerNode otherNode = (BigIntegerNode) o;
if (o instanceof BigIntegerNode otherNode) {
return Objects.equals(otherNode._value, _value);
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/node/BinaryNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof BinaryNode) {
byte[] otherData = ((BinaryNode) o)._data;
if (o instanceof BinaryNode binaryNode) {
byte[] otherData = binaryNode._data;
return Arrays.equals(_data, otherData);
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tools/jackson/databind/node/BooleanNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public boolean equals(Object o)
*/
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof BooleanNode)) {
return false;
if (o instanceof BooleanNode otherNode) {
return (_value == otherNode._value);
}
return (_value == ((BooleanNode) o)._value);
return false;
}
}
3 changes: 1 addition & 2 deletions src/main/java/tools/jackson/databind/node/DecimalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof DecimalNode) {
DecimalNode otherNode = (DecimalNode) o;
if (o instanceof DecimalNode otherNode) {
return otherNode._value.equals(_value);
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/node/DoubleNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof DoubleNode) {
if (o instanceof DoubleNode otherNode) {
// We must account for NaNs: NaN does not equal NaN, therefore we have
// to use Double.compare().
final double otherValue = ((DoubleNode) o)._value;
final double otherValue = otherNode._value;
return Double.compare(_value, otherValue) == 0;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/node/FloatNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof FloatNode) {
if (o instanceof FloatNode otherNode) {
// We must account for NaNs: NaN does not equal NaN, therefore we have
// to use Float.compare().
final float otherValue = ((FloatNode) o)._value;
final float otherValue = otherNode._value;
return Float.compare(_value, otherValue) == 0;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/node/IntNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof IntNode) {
return ((IntNode) o)._value == _value;
if (o instanceof IntNode otherNode) {
return otherNode._value == _value;
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/node/LongNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof LongNode) {
return ((LongNode) o)._value == _value;
if (o instanceof LongNode otherNode) {
return otherNode._value == _value;
}
return false;
}
Expand Down
41 changes: 20 additions & 21 deletions src/main/java/tools/jackson/databind/node/ObjectNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ protected ObjectNode _withObject(JsonPointer origPtr,

JsonNode n = _at(currentPtr);
// If there's a path, follow it
if ((n != null) && (n instanceof BaseJsonNode)) {
ObjectNode found = ((BaseJsonNode) n)._withObject(origPtr, currentPtr.tail(),
if (n instanceof BaseJsonNode baseNode) {
ObjectNode found = baseNode._withObject(origPtr, currentPtr.tail(),
overwriteMode, preferIndex);
if (found != null) {
return found;
Expand All @@ -163,8 +163,8 @@ protected ArrayNode _withArray(JsonPointer origPtr,

JsonNode n = _at(currentPtr);
// If there's a path, follow it
if ((n != null) && (n instanceof BaseJsonNode)) {
ArrayNode found = ((BaseJsonNode) n)._withArray(origPtr, currentPtr.tail(),
if (n instanceof BaseJsonNode baseNode) {
ArrayNode found = baseNode._withArray(origPtr, currentPtr.tail(),
overwriteMode, preferIndex);
if (found != null) {
return found;
Expand Down Expand Up @@ -328,25 +328,24 @@ public void forEachEntry(BiConsumer<? super String, ? super JsonNode> action) {
@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
if (!(o instanceof ObjectNode)) {
return false;
}
ObjectNode other = (ObjectNode) o;
Map<String, JsonNode> m1 = _children;
Map<String, JsonNode> m2 = other._children;

final int len = m1.size();
if (m2.size() != len) {
return false;
}
if (o instanceof ObjectNode other) {
Map<String, JsonNode> m1 = _children;
Map<String, JsonNode> m2 = other._children;

for (Map.Entry<String, JsonNode> entry : m1.entrySet()) {
JsonNode v2 = m2.get(entry.getKey());
if ((v2 == null) || !entry.getValue().equals(comparator, v2)) {
final int len = m1.size();
if (m2.size() != len) {
return false;
}

for (Map.Entry<String, JsonNode> entry : m1.entrySet()) {
JsonNode v2 = m2.get(entry.getKey());
if ((v2 == null) || !entry.getValue().equals(comparator, v2)) {
return false;
}
}
return true;
}
return true;
return false;
}

/*
Expand Down Expand Up @@ -1030,8 +1029,8 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof ObjectNode) {
return _childrenEqual((ObjectNode) o);
if (o instanceof ObjectNode objectNode) {
return _childrenEqual(objectNode);
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/node/POJONode.java
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof POJONode) {
return _pojoEquals((POJONode) o);
if (o instanceof POJONode pojoNode) {
return _pojoEquals(pojoNode);
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/databind/node/ShortNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof ShortNode) {
return ((ShortNode) o)._value == _value;
if (o instanceof ShortNode other) {
return other._value == _value;
}
return false;
}
Expand Down
Loading