-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
3.0Issue planned for initial 3.0 releaseIssue planned for initial 3.0 release
Milestone
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
When calling mapper.valueToTree(UUID.randomUUID()), a NullPointerException is thrown inside the private _writeAsBinary(...) method.
The root cause is that _writeCapabilities is null when ctxt.isEnabled(...) is checked.
Version Information
3.0.0-rc5
Reproduction
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.valueToTree(UUID.randomUUID());
Expected behavior
No NullPointerException is thrown
Additional context
The root cause is that _assignGenerator isn’t called when valueToTree is invoked; since valueToTree isn’t actually performing serialization, it’s appropriate to handle it by not calling _assignGenerator.
here seem to be two possible approaches:
- Null-check in isEnabled
Add a null check for _writeCapabilities inside isEnabled, and return false if it’s null. This is safe because valueToTree doesn’t actually serialize—instead, the JsonNode simply holds the UUID as a string.
public final boolean isEnabled(StreamWriteCapability cap) {
return _wirteCapabilities != null && _writeCapabilities.isEnabled(cap);
}
- Default initialization in the SerializationContext
Initialize _writeCapabilities with a default value when the SerializationContext is created. This ensures it’s never null, but may be wasteful since a fresh capabilities object will be created anyway once actual serialization occurs.
JacksonFeatureSet<StreamWriteCapability> _writeCapabilities
= JacksonFeatureSet.fromDefaults(StreamWriteCapability.values());
anthologia
Metadata
Metadata
Assignees
Labels
3.0Issue planned for initial 3.0 releaseIssue planned for initial 3.0 release