Minor improvement to `WritableObjectId`
diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x
index f8724a9..f868edf 100644
--- a/release-notes/VERSION-2.x
+++ b/release-notes/VERSION-2.x
@@ -10,7 +10,9 @@
(reported by Thomas K)
#2221: `DeserializationProblemHandler.handleUnknownTypeId()` returning `Void.class`,
enableDefaultTyping causing NPE
- (repoted by MeyerNils@github)
+ (reported by MeyerNils@github)
+- Prevent String coercion of `null` in `WritableObjectId` when calling `JsonGenerator.writeObjectId()`,
+ mostly relevant for formats like YAML that have native Object Ids
2.9.8 (15-Dec-2018)
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/WritableObjectId.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/WritableObjectId.java
index d842694..5975930 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/WritableObjectId.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/WritableObjectId.java
@@ -64,12 +64,17 @@
// 03-Aug-2013, tatu: Prefer Native Object Ids if available
if (gen.canWriteObjectId()) {
// Need to assume String(ified) ids, for now... could add 'long' variant?
- gen.writeObjectId(String.valueOf(id));
+ // 05-Feb-2019, tatu: But in special case of `null` we should not coerce -- whether
+ // we should even call is an open question, but for now do pass to let generator
+ // decide what to do, if anything.
+ String idStr = (id == null) ? null : String.valueOf(id);
+ gen.writeObjectId(String.valueOf(idStr));
return;
}
-
+
SerializableString name = w.propertyName;
if (name != null) {
+ // 05-Feb-2019, tatu: How about `null` id? For now, write
gen.writeFieldName(name);
w.serializer.serialize(id, gen, provider);
}