readValue and readTree in Jackson: when to use which?

前端 未结 2 1819
旧时难觅i
旧时难觅i 2021-02-02 09:35

I\'m just starting using the Jackson JSON library. Jackson is a very powerful library, but it has a terribly extensive API. A lot of things can be done in multiple ways. This ma

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 10:29

    readValue() can be used for any and all types, including JsonNode. readTree() only works for JsonNode (tree model); and is added for convenience.

    Note that you NEVER want to use your first example: it is equivalent to writing out your node as JSON, then reading it back -- just cast it.

提交回复
热议问题