Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support nulls in TextNode equals #4379

Merged
merged 5 commits into from
Feb 13, 2024
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
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.databind.node;

import java.io.IOException;
import java.util.Objects;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.CharTypes;
Expand Down Expand Up @@ -164,13 +165,16 @@ public boolean equals(Object o)
if (o == this) return true;
if (o == null) return false;
if (o instanceof TextNode) {
return ((TextNode) o)._value.equals(_value);
TextNode otherNode = (TextNode) o;
return Objects.equals(otherNode._value, _value);
}
return false;
}

@Override
public int hashCode() { return _value.hashCode(); }
public int hashCode() {
return Objects.hashCode(_value);
}

@Deprecated // since 2.10
protected static void appendQuoted(StringBuilder sb, String content)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fasterxml.jackson.databind.node;

import static org.junit.Assert.assertNotEquals;

public class TextNodeTest extends NodeTestBase
{
public void testText()
Expand Down Expand Up @@ -36,4 +38,19 @@ public void testText()
assertFalse(TextNode.valueOf("false").asBoolean(true));
assertFalse(TextNode.valueOf("false").asBoolean(false));
}

public void testEquals()
{
assertEquals(new TextNode(null), new TextNode(null));
assertEquals(new TextNode("abc"), new TextNode("abc"));
assertNotEquals(new TextNode(null), new TextNode("def"));
assertNotEquals(new TextNode("abc"), new TextNode("def"));
assertNotEquals(new TextNode("abc"), new TextNode(null));
}

public void testHashCode()
{
assertEquals(0, new TextNode(null).hashCode());
assertEquals("abc".hashCode(), new TextNode("abc").hashCode());
}
}