2016-08-05 10 views

答えて

2

は、カスタム書式を定義する必要があります。

object MyJsonProtocol extends DefaultJsonProtocol { 
    implicit object ColorJsonFormat extends RootJsonFormat[Color] { 
       def write(c: Color) = c match { 
        case VColor => JsString("v_color") 
        case _ => JsString("foo") 
       } 

       def read(value: JsValue) = ??? 
    } 

    implicit val customColorFormat = jsonFormat1(CustomColor.apply) 
} 

その後

[email protected] import MyJsonProtocol._ 
[email protected] CustomColor(VColor).toJson 
res18: JsValue = {"c":"v_color"} 
関連する問題