Skip to content

empty string / whitespace string in json should not be JsonNullable.undefined() for JsonNullable<String> #3

@hatzlj

Description

@hatzlj

I had some trouble understanding the rationale behind

@Override
public JsonNullable<Object> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING && !_fullType.isTypeOrSubTypeOf(String.class)) {
String str = p.getText().trim();
if (str.isEmpty()) {
return JsonNullable.undefined();
}
}
return super.deserialize(p, ctxt);
}

and took a closer look on the code and tests. I think that the check in line 40 should compare the generic type of JsonNullable rather than the _fullType - otherwise it would replace empty/whitespace strings with JsonNullable.undefined() for any type, since _fullType always is JsonNullable in the Deserializer.

Unfortunately there was no test covering the null/empty string case for JsonNullable, so this behaviour kept undiscovered.

I`ll submit a pull request to fix that bug / add additonal tests to cover the case and would be happy to see it upstream soon if you agree.

Thanks,
Jakob

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions