开发者

Jackson: deserializing (parsing) null Unicode

I use Jackson to deserialize (parse) a simple JSON event, with code like this:

JsonParser parser = ... // Initialized via JsonFactory for simple JSON String
ObjectMapper mapper = new ObjectMapper();
HashMap<String, Object> attributes = mapper.readValue(parser,
                     new TypeReference<HashMap&开发者_JAVA百科lt;String, Object>>() {});

The code works as expected for the several cases I have tested it against, apart from when the JSON input contains the Unicode null value (\u0000).

More specifically, if the JSON String above has a key-value pair that contains Unicode, e.g.

{
... (start K-V pairs),
"UniKey":"\u0000...",
... (end K-V pairs)
}

the parser correctly reads all "start K-V pairs" (which contain no null Unicode) into the attributes HashMap but stops deserialization immediately on encountering the null Unicode value of "UniKey", returning an empty value and never parsing the rest of the JSON String (i.e., the "end K-V pairs").

Is there any way of telling Jackson to ignore null Unicode in deserialization?


Strings containing null (\u0000) are read/printed by some Java methods and not by others, so they are only displayed as truncated. So the value may actually be there, but not displayed by something like System.out.println().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜