简体   繁体   中英

Cleanest way to deserialize a non-standard (wrong) format of list of JSON string that doesn't have quote

I'm trying to deserialize a Java String to a List of String . Due to some reason, the input may come in two formats:

"[\"string1\", \"string2\"]"

or

"[string1, string2]"

The library I'm using is Jackson databind.

For the first case, it's a typical, easy case that Jackson supports.

For the second, I understand it's not a correct format of JSON and I can hack to achieve the goal by splitting this String by , and remove [] s etc, but just would like to know if someone knows a clean way to deserialize something like that.

Thanks in advance.

To answer your question, you can look into YAML parsers. :)
Jackson has an extention for YAML support so that would be your clean solution.
YAML is a superset of JSON so it can parse any valid JSON... as well as many more complex transcripts (like strings without " ).

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