I am creating a Finch endpoint which expects a Json.
URL - LogBundles/Long JSON Message/Process
I am using json4s library for Json parsing
How do I specify the body as type json Or how do I pass a Json value between LogBundles and Process?
I cannot do body.as[case class] because I wont be knowing the exact structure of Json. I will be just looking out for a specific key while parsing.
Code
val bundleProcessEndpoint: Endpoint[String] = put("LogBundles" :: body :: "Process" ) { id =>
val jsonBody = parse(id)}
ERROR
could not find implicit value for parameter d: io.finch.Decode.Aux[A,CT] [error] val bundleProcessEndpoint: Endpoint[String] = put("LogBundles" :: body :: "Process" ) { id:JsonInput =>
There are several ways of doing this, although none of them is considered idiomatic for Finch. The more-or-less safe way to accept an arbitrary JSON object within an
Endpointis to drop down to JSON AST API exposed via the JSON library you're using. For json4s it's going to beorg.json4s.JsonAST.JValue.This will give you a
JsonAST.JValueinstance that you'd need to manually manipulate with (I assume there is a pattern-matching API exposed for that).An alternative (and way more dangerous) solution would be to ask Finch/JSON4S to decode a JSON object as
Map[String, Any]. However, this only works if you don't expect your clients sending JSON arrays as top-level entities.