Sample Json:
var testString = {"eventType":"REQUEST","event-id":"6e904afa-62e8-40fb-8c6a-66a2ba21a3e1"}
Scala case class:
case class EventHeader(eventType:String,event-id:String)
De-serialization code:
var header = new Gson().fromJson(testString,classOf[EventHeader])
Resulting in following error (because of special character in "event-id" field name):
:1: error: ':' expected but identifier found. case class EventHeader(eventType:String,event-id:String)
In Java we can have an annotation on "event-id" field and name it as "eventId" or "id".
Is there a similar way in Scala?