简体   繁体   中英

jackson objectMapper.readValue fails on empty values

I'm trying to read this json file into a Map { "1": 0, "2": 1, "3": , "4": 5 } my json is very simple but as you see in the example it can have a key with an empty value (null value) on "3". parsing it by:

    Map<String, Object> testMap = objectMapper.readValue(file.getInputStream(), Map.class);

fails with "Unexpected character (',' (code 44)): expected a value"

is there any way to make this work?

Thanks

{ "1": 0, "2": 1, "3": , "4": 5 } is not a valid JSON, so any standard parser would fail. You can customize a parser or (better) use a regex to substitute the "key": , with "key": null, .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM