How to unlimit spray jsonFormat

北城以北 提交于 2019-12-01 06:23:09

If you are referring to the methods in the ProductFormatsInstances trait, there are versions of jsonFormat up to 22 parameters. If you have a case class with more than 22 parameters, I see two immediate options. Suppose you have

case class Client(..., address: Address, telephone: Telephone, email: Email, ...)
  • Options 1: reduce the number of parameters by breaking down the Client class into finer-grained classes taking fewer parameters.. For example, you can refactor to the following.

    case class ClientContact(address: Address, telephone: Telephone, email: Email)
    case class Client(..., contact: ClientContact, ...)
    
  • Options 2: write a custom serialiser by implementing RootJsonFormat. See here for an example.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!