-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty CSV string deserialized as String containing "null"
instead of null
String
#330
Comments
null
String for empty CSV string deserialized as String "null" instead of nullnull
String
null
String"null"
instead of null
String
Will move to the right repository for CSV format issues. |
Thank you for reporting this: it sounds like a possible bug. Thank you for also including reproduction. |
Hmmmh. Unfortunately I am unable to reproduce this on my side, with test like:
so I think I'd need some help here. |
Thanks for your speedy response @cowtowncoder! So I looked in to this some more this morning, and I managed to track down the source of the issue I was experiencing. import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@JsonDeserialize(using = Row330Deserializer.class)
public class Row330 {
public Integer id;
public String value = "default";
public Row330(
Integer id,
String value
) {
this.id = id;
this.value = value;
}
}
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
public class Row330Deserializer extends JsonDeserializer<Row330> {
@Override
public Row330 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
JsonNode node = p.readValueAsTree();
return new Row330(
node.get("id").asInt(),
node.get("value").asText()
);
}
} When using this set up, I believe your test above will fail, as |
I think it works as expected: Whether that makes sense or not would be an issue for |
Understandable. Thanks for helping me with my problem @cowtowncoder, even though it turned out to not be a bug! |
No problem @jhanlonhg ! Just glad we were able to figure it out. |
Describe the bug
When attempting to deserialize a CSV with empty strings to an object with string fields, the fields are populated with
"null"
instead of the expectednull
. Note that this is using theCsvParser.Feature.EMPTY_STRING_AS_NULL
feature.Version information
2.13.3
To Reproduce
My project is using this code to deserialize CSV into a set of POJO objects:
We are expecting that given a class like so:
We would deserialize a CSV like this:
Into an object containing
Instead, we are experiencing
Expected behavior
That given the code above, empty strings in a CSV will be deserialized to a
null
String object, instead of a String containing "null".Additional context
Similar to this issue here, only in a different context. Furthermore, I assume that the underlying issue is the same:
The text was updated successfully, but these errors were encountered: