You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some simple cases, it would be nice to support automatic generation of a DSL given a case class. Similar to what the Kotlin implementation offers with basedOnRequiredConstructorFields.
Expected usage would be something like following:
caseclassMyModel(a: String, b: Int, c: NestedModel)
caseclassNestedModel(x: Seq[Long])
valdsl=DslJsonBodyBuilder.fromType[MyModel]
// Gives a LambdaDslJsonBody => Unit// Same as what would be given to:
newJsonObject { rootObj =>
rootObj.stringType("a")
rootObj.integerType("b")
rootObj.newObject("c") { o =>
o.newArray("x") { a =>
a.longType()
}
}
}
We could also provide a helper in ScalaDsl (#355 ):
newJsonObject[MyModel]
The generated DSL would be using matching types, not values.
To implement that, we will need to use TypeTag but this won't be available in Scala 3 (there are other alternatives in Scala 3). This would mean a different codebase for Scala 2 & Scala 3 which is perfectly possible but I believe the sbt structure does not allow it for now.
The text was updated successfully, but these errors were encountered:
Giving it a 2nd thought, maybe a simpler approach could be to expose a bodyForm(case class instance) method which would act similar to the existing body(...) but would take benefit of the JSON encoder provided by the user though it's library of choice (Circe, play JSON..) to generate a DSL given an actual JSON value.
This feels a bit like a hack though as we should not need a JSON library to generate a DSL from a case class and we would have to do the work once for each library.
On the other hand, it could be a simpler approach and it would reuse potentially custom encoders written by the user.
In some simple cases, it would be nice to support automatic generation of a DSL given a case class. Similar to what the Kotlin implementation offers with
basedOnRequiredConstructorFields
.Expected usage would be something like following:
We could also provide a helper in
ScalaDsl
(#355 ):newJsonObject[MyModel]
The generated DSL would be using matching types, not values.
To implement that, we will need to use
TypeTag
but this won't be available in Scala 3 (there are other alternatives in Scala 3). This would mean a different codebase for Scala 2 & Scala 3 which is perfectly possible but I believe the sbt structure does not allow it for now.The text was updated successfully, but these errors were encountered: