Skip to content

JsonParser from MismatchedInputException cannot getText() for floating-point value #2770

@joca-bt

Description

@joca-bt

I've stumbled upon another situation in which I'm not able to get the textual representation of the current token.

I have the following class:

public class Test {
    public Boolean value;
    public Boolean getValue() { return value; }
    public void setValue(Boolean value) { this.value = value; }
}

And the following object mapper:

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS);

I'm trying to deserialize something that would result in a MismatchedInputException: I'm providing a number to something that expects a boolean:

try {
    objectMapper.readValue("{ \"value\": 1.0 }", Test.class);
} catch (MismatchedInputException exception) {
    JsonParser parser = (JsonParser) exception.getProcessor();
    System.out.println(parser.currentToken());
    System.out.println(parser.getText());
} catch (Exception exception) {}

This results in:

VALUE_NUMBER_FLOAT

while I would expect parser.getText() to return "1.0".

Related with #2635. However that one was specifically for InputStreams, where here it happens for both Strings and InputStreams.

(Jackson 2.11.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions