Using Lenses on Scala Regular Classes

前端 未结 2 439
青春惊慌失措
青春惊慌失措 2021-01-21 02:42

Most popular JSON libraries for Scala have the ability to serialize and deserialize to case classes.

Unfortunately, until Scala 2.11 is released, there is a restriction

2条回答
  •  臣服心动
    2021-01-21 03:06

    If you're using lenses anyway, just nest your case classes. You'll have more potential for reuse of data, and the main reason not to nest is to avoid monstrosities like

    record.copy(person = record.person.copy(name = record.person.name.capitalize))
    

    which are (largely) solved if you use lenses. JSON can handle nested classes.

提交回复
热议问题