How to parse request body and route param into nested case class

17 views
Skip to first unread message

sbaldwin

unread,
Dec 15, 2017, 8:43:42 PM12/15/17
to finatra-users
Hello
I have a question about Request deserialization. Lets say I have a route such as post("/example/:id") that requires a request body matching the following existing case class: "case class ExampleModel(first: String, last: String)".

Now lets say that I would like to map both the id RouteParam and ExampleModel body into a single case class and use that for the request. I know that I can create a new case class that has (@RouteParam id: String, first: String, last: String) but what I would really like to do is have "case class ExampleRequest(@RouteParam id: String, model: ExampleModel)" and use that in place of Request. Is it possible to define this type of mapping?

Thanks for the help.

Christopher Coco

unread,
Dec 17, 2017, 11:58:34 AM12/17/17
to sbaldwin, finatra-users
For nested parsing of the request like this, you can create and install a MessageBodyReader. See the test (and it's associated classes) for usage patterns along with the larger example usage in the tweetexample integration test.

Thanks,
-c


--
You received this message because you are subscribed to the Google Groups "finatra-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to finatra-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sbald...@gmail.com

unread,
Dec 18, 2017, 12:48:03 PM12/18/17
to finatra-users
Ah excellent thanks for the help!
Reply all
Reply to author
Forward
0 new messages