how to use special character in scala case class

时间:2016-04-07 10:32:17

标签: scala class case

I am consuming the JSON below,

{
  "@context": "Testingcontext",
  "@type": "Testingtype",
  "actor": "Testingactor"
}

for which I am creating a case class in scala:

case class LoggedInAction(`@context`: String,`@type`:String,actor:String) 

How can I use special character like @, & in a case class? Also, how to use such case class fields?

1 个答案:

答案 0 :(得分:2)

正如您在示例中所做的那样:

scala> case class LoggedInAction(`@context`: String,`@type`:String,actor:String)
defined class LoggedInAction

scala> val example = LoggedInAction("context", "type", "actor")
example: LoggedInAction = LoggedInAction(context,type,actor)

scala> example.`@context`
res0: String = context