Scala: Parse JSON directly into a case class

后端 未结 7 2236
一生所求
一生所求 2020-12-24 11:36

Given a string of JSON, and a case class that corresponds to it, what\'s a simple way to parse the JSON into the case class? There are many libraries available, but it seem

7条回答
  •  悲哀的现实
    2020-12-24 12:09

    Spray Json is pretty light weight and does exactly what you need. It's a toolkit instead of a full on framework and you can just import the Spray-json project instead of the entire project.

    https://github.com/spray/spray-json

    The examples can get you set up very quickly. Most of the time your code to translate to/from JSON ends up being one liners, but you have the ability to explicitly handle it in case you have some weird requirements.

提交回复
热议问题