Skip to content

Commit

Permalink
Fix #2566
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 11, 2019
1 parent 0f91036 commit ae7808e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,8 @@ Fabian Lange (CodingFabian@github)
Stefan Wendt (stewe@github)
* Reported #2560: Check `WRAP_EXCEPTIONS` in `CollectionDeserializer.handleNonArray()`
(2.10.2)
Greg Arakelian (arakelian@github)
* Reported #2566: `MissingNode.toString()` returns `null` (4 character token) instead
of empty string
(2.10.2)
4 changes: 3 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Project: jackson-databind
#2560: Check `WRAP_EXCEPTIONS` in `CollectionDeserializer.handleNonArray()`
(reported by Stefan W)
#2564: Fix `IllegalArgumentException` on empty input collection for `ArrayBlockingQueue`
(repoted, fix suggested by yamert89@github)
(reported, fix suggested by yamert89@github)
#2566: `MissingNode.toString()` returns `null` (4 character token) instead of empty string
(reported by Greg A)
#2567: Incorrect target type for arrays when providing nulls and nulls are disabled
(reported by João G)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public abstract void serializeWithType(JsonGenerator jgen, SerializerProvider pr

/*
/**********************************************************
/* Std method overrides
/* Standard method overrides
/**********************************************************
*/

Expand Down
60 changes: 44 additions & 16 deletions src/main/java/com/fasterxml/jackson/databind/node/MissingNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ public JsonNodeType getNodeType()
public double asDouble(double defaultValue);
public boolean asBoolean(boolean defaultValue);
*/

/*
/**********************************************************
/* Serialization: bit tricky as we don't really have a value
/**********************************************************
*/

@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
public final void serialize(JsonGenerator g, SerializerProvider provider)
throws IOException, JsonProcessingException
{
/* Nothing to output... should we signal an error tho?
Expand All @@ -81,7 +87,7 @@ public final void serialize(JsonGenerator jg, SerializerProvider provider)
* cannot just omit a value as JSON Object field name may have
* been written out.
*/
jg.writeNull();
g.writeNull();
}

@Override
Expand All @@ -91,21 +97,13 @@ public void serializeWithType(JsonGenerator g, SerializerProvider provider,
{
g.writeNull();
}

@Override
public boolean equals(Object o)
{
/* Hmmh. Since there's just a singleton instance, this
* fails in all cases but with identity comparison.
* However: if this placeholder value was to be considered
* similar to SQL NULL, it shouldn't even equal itself?
* That might cause problems when dealing with collections
* like Sets... so for now, let's let identity comparison
* return true.
*/
return (o == this);
}

/*
/**********************************************************
/* Jackson 2.10 improvements for validation
/**********************************************************
*/

@SuppressWarnings("unchecked")
@Override
public JsonNode require() {
Expand All @@ -122,4 +120,34 @@ public JsonNode requireNonNull() {
public int hashCode() {
return JsonNodeType.MISSING.ordinal();
}

/*
/**********************************************************
/* Standard method overrides
/**********************************************************
*/

// 10-Dec-2019, tatu: Bit tricky case, see [databind#2566], but seems
// best NOT to produce legit JSON.
@Override
public String toString() {
return "";
}

@Override
public String toPrettyString() {
return "";
}

@Override
public boolean equals(Object o)
{
/* Hmmh. Since there's just a singleton instance, this fails in all cases but with
* identity comparison. However: if this placeholder value was to be considered
* similar to SQL NULL, it shouldn't even equal itself?
* That might cause problems when dealing with collections like Sets...
* so for now, let's let identity comparison return true.
*/
return (o == this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public void testMissing()
assertEquals("", n.asText());
assertStandardEquals(n);
// 10-Dec-2018, tatu: With 2.10, should serialize same as via ObjectMapper/ObjectWriter
assertEquals("null", n.toString());
// 10-Dec-2019, tatu: Surprise! No, this is not how it worked in 2.9, nor does it make
// sense... see [databind#2566] for details
assertEquals("", n.toString());

assertNodeNumbersForNonNumeric(n);

Expand Down

0 comments on commit ae7808e

Please sign in to comment.