Skip to content

Commit ae7808e

Browse files
committed
Fix #2566
1 parent 0f91036 commit ae7808e

File tree

5 files changed

+56
-19
lines changed

5 files changed

+56
-19
lines changed

release-notes/CREDITS-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,8 @@ Fabian Lange (CodingFabian@github)
10121012
Stefan Wendt (stewe@github)
10131013
* Reported #2560: Check `WRAP_EXCEPTIONS` in `CollectionDeserializer.handleNonArray()`
10141014
(2.10.2)
1015+
1016+
Greg Arakelian (arakelian@github)
1017+
* Reported #2566: `MissingNode.toString()` returns `null` (4 character token) instead
1018+
of empty string
1019+
(2.10.2)

release-notes/VERSION-2.x

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Project: jackson-databind
1515
#2560: Check `WRAP_EXCEPTIONS` in `CollectionDeserializer.handleNonArray()`
1616
(reported by Stefan W)
1717
#2564: Fix `IllegalArgumentException` on empty input collection for `ArrayBlockingQueue`
18-
(repoted, fix suggested by yamert89@github)
18+
(reported, fix suggested by yamert89@github)
19+
#2566: `MissingNode.toString()` returns `null` (4 character token) instead of empty string
20+
(reported by Greg A)
1921
#2567: Incorrect target type for arrays when providing nulls and nulls are disabled
2022
(reported by João G)
2123

src/main/java/com/fasterxml/jackson/databind/node/BaseJsonNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public abstract void serializeWithType(JsonGenerator jgen, SerializerProvider pr
127127

128128
/*
129129
/**********************************************************
130-
/* Std method overrides
130+
/* Standard method overrides
131131
/**********************************************************
132132
*/
133133

src/main/java/com/fasterxml/jackson/databind/node/MissingNode.java

+44-16
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ public JsonNodeType getNodeType()
7070
public double asDouble(double defaultValue);
7171
public boolean asBoolean(boolean defaultValue);
7272
*/
73+
74+
/*
75+
/**********************************************************
76+
/* Serialization: bit tricky as we don't really have a value
77+
/**********************************************************
78+
*/
7379

7480
@Override
75-
public final void serialize(JsonGenerator jg, SerializerProvider provider)
81+
public final void serialize(JsonGenerator g, SerializerProvider provider)
7682
throws IOException, JsonProcessingException
7783
{
7884
/* Nothing to output... should we signal an error tho?
@@ -81,7 +87,7 @@ public final void serialize(JsonGenerator jg, SerializerProvider provider)
8187
* cannot just omit a value as JSON Object field name may have
8288
* been written out.
8389
*/
84-
jg.writeNull();
90+
g.writeNull();
8591
}
8692

8793
@Override
@@ -91,21 +97,13 @@ public void serializeWithType(JsonGenerator g, SerializerProvider provider,
9197
{
9298
g.writeNull();
9399
}
94-
95-
@Override
96-
public boolean equals(Object o)
97-
{
98-
/* Hmmh. Since there's just a singleton instance, this
99-
* fails in all cases but with identity comparison.
100-
* However: if this placeholder value was to be considered
101-
* similar to SQL NULL, it shouldn't even equal itself?
102-
* That might cause problems when dealing with collections
103-
* like Sets... so for now, let's let identity comparison
104-
* return true.
105-
*/
106-
return (o == this);
107-
}
108100

101+
/*
102+
/**********************************************************
103+
/* Jackson 2.10 improvements for validation
104+
/**********************************************************
105+
*/
106+
109107
@SuppressWarnings("unchecked")
110108
@Override
111109
public JsonNode require() {
@@ -122,4 +120,34 @@ public JsonNode requireNonNull() {
122120
public int hashCode() {
123121
return JsonNodeType.MISSING.ordinal();
124122
}
123+
124+
/*
125+
/**********************************************************
126+
/* Standard method overrides
127+
/**********************************************************
128+
*/
129+
130+
// 10-Dec-2019, tatu: Bit tricky case, see [databind#2566], but seems
131+
// best NOT to produce legit JSON.
132+
@Override
133+
public String toString() {
134+
return "";
135+
}
136+
137+
@Override
138+
public String toPrettyString() {
139+
return "";
140+
}
141+
142+
@Override
143+
public boolean equals(Object o)
144+
{
145+
/* Hmmh. Since there's just a singleton instance, this fails in all cases but with
146+
* identity comparison. However: if this placeholder value was to be considered
147+
* similar to SQL NULL, it shouldn't even equal itself?
148+
* That might cause problems when dealing with collections like Sets...
149+
* so for now, let's let identity comparison return true.
150+
*/
151+
return (o == this);
152+
}
125153
}

src/test/java/com/fasterxml/jackson/databind/node/TestMissingNode.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public void testMissing()
1616
assertEquals("", n.asText());
1717
assertStandardEquals(n);
1818
// 10-Dec-2018, tatu: With 2.10, should serialize same as via ObjectMapper/ObjectWriter
19-
assertEquals("null", n.toString());
19+
// 10-Dec-2019, tatu: Surprise! No, this is not how it worked in 2.9, nor does it make
20+
// sense... see [databind#2566] for details
21+
assertEquals("", n.toString());
2022

2123
assertNodeNumbersForNonNumeric(n);
2224

0 commit comments

Comments
 (0)