I have 3 case classes which are having cyclic reference for nested field each other as below.
case class DataSource(subQuery: Query,name:String)
case class JoinQuery(joinType:String,query:Query)
case class Query(child:DataSource, joinQuery:Seq[JoinQuery])
I want to write a companion class for these with Json formater class to parse json to case class and vice versa. How can I achieve this ? I tried the answer mentioned below but with no luck.
Sorry but this is not a proper description of what you did and what error you got.
I didn't manage to make automated mappings work without
NullPointerExceptions but the approach with recursive types seems to work.DataSourcedepends onQueryandQuerydepends onDataSource, so it's not clear how you're going to instantiate these classes. Probably withnulls, so at least some of the fields should be optional. For example I modified this place:case class Query(child:Option[DataSource], ...)