Skip to content

Conversion of MissingNode throws JsonProcessingException #4932

Closed
@ludgerb

Description

@ludgerb

According to the documentation about MissingNode the following holds:

In most respects this placeholder node will act as NullNode; for example, for purposes of value conversions, value is considered to be null and represented as value zero when used for numeric conversions.

While this holds true for most operation, this fails when converting a json tree containing a MissingNode to a Pojo.

Version Information

2.18.0

Reproduction

  @Test
  void testTreeToValue() throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();

    // Success
    var result = assertDoesNotThrow(() -> objectMapper.treeToValue(NullNode.getInstance(), Object.class));
    assertNull(result);

    // Fails
    result = assertDoesNotThrow(() -> objectMapper.treeToValue(MissingNode.getInstance(), Object.class));
    assertNull(result);
  }

Expected behavior

Expected behavior:
converting a MissingNode should behave the same as converting the NullNode

Observed behavior:
converting a NullNode returns a null reference.
converting a MissingNode throws a JsonProcessingException.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.18Issues planned at 2.18 or later

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions