2017-10-07 39 views
0

什麼是使用多個FieldSerializer的正確語法?我試圖重新命名3場只工作,如果我使用Concat的DefaultFormatsjson4s - 如何使用多個FieldSerializer

val currg = FieldSerializer[Currency](renameTo("gameCurr", "gameCurr"), renameFrom("currg", "gameCurr")) 
val curre = FieldSerializer[Currency](renameTo("currency", "currency"), renameFrom("curre", "currency")) 
val lprice = FieldSerializer[Currency](renameTo("price", "price"), renameFrom("lprice", "price")) 

implicit val formats = org.json4s.DefaultFormats + lprice //+ curre + currg 

其中之一。如果我只讓一個FieldSerializer,它就像一個魅力

implicit val formats = org.json4s.DefaultFormats + lprice 

回答

0

您可以重命名多個字段在單個FieldSerializerorElse

val rename_currency_fields = FieldSerializer[Currency](
    renameTo("foo", "bar") orElse renameTo("baz", "qux") 
    renameFrom("bar", "foo") orElse renameFrom("qux", "baz") 
) 

implicit val formats = org.json4s.DefaultFormats + rename_currency_fields