How to parse a JSON string into JsonNode in Jackson?

前端 未结 6 1494
星月不相逢
星月不相逢 2020-11-29 15:55

It should be so simple, but I just cannot find it after being trying for an hour #embarrasing.

I need to get a JSON string, for example, {\"k1\":v1,\"k2\":v2}<

6条回答
  •  悲哀的现实
    2020-11-29 16:04

    Richard's answer is correct. Alternatively you can also create a MappingJsonFactory (in org.codehaus.jackson.map) which knows where to find ObjectMapper. The error you got was because the regular JsonFactory (from core package) has no dependency to ObjectMapper (which is in the mapper package).

    But usually you just use ObjectMapper and do not worry about JsonParser or other low level components -- they will just be needed if you want to data-bind parts of stream, or do low-level handling.

提交回复
热议问题