Generate Recursive Tree of Types of Case Class (with shapeless)

46 Views Asked by At

I would like to generate a tree of types starting from a given case class, without instantiating a value

Example:

case class C1(x: Int)
case class C2(s: String, b: Boolean
case class C3(c1: C1, c2: String)

Which forms a tree like this:

C3
|
+-- C1
|   |
|   +-- Int
|
+-- C2
    |
    +-- String
    |
    +-- Boolean

Approx. expected output, does not have to be JSON but a similar (ideally isomorphic) structure:

{
  "_type": "C3"
  "c1": {
    "_type": "C1",
    "x": { "_type": "Int" }
  },
  "c2": {
    "_type": "C2",
    "s": { "_type": "String" },
    "b": { "_type": "Boolean" }
  }
}


It seems like LabelledGeneric is what I want, but I need to recursively traverse down somehow. Also, Typeable seems to be able to generate a String representation of a type already.

0

There are 0 best solutions below