From aa2da50a2db223ca52d6de6c7203ca364480cdc5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Fri, 14 Oct 2016 20:58:55 -0400 Subject: [PATCH] nitrestful & lib: use static type to limit and as heuristic at deserialization MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/nitcorn/restful.nit | 6 +++--- src/nitrestful.nit | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/nitcorn/restful.nit b/lib/nitcorn/restful.nit index abaaf0d..af3fe1d 100644 --- a/lib/nitcorn/restful.nit +++ b/lib/nitcorn/restful.nit @@ -62,18 +62,18 @@ class RestfulAction redef fun answer(request, truncated_uri) do return new HttpResponse(400) - # Service to deserialize arguments from JSON + # Deserialize `val` from JSON for a parameter typed by `static_type` # # Accepts `nullable String` for convenience, but returns `null` when `val == null`. # # This method is called by the code generated by `nitrestful`. # It can be specialized to customize its behavior. - protected fun deserialize_arg(val: nullable String): nullable Object + protected fun deserialize_arg(val: nullable String, static_type: String): nullable Object do if val == null then return null var deserializer = new JsonDeserializer(val) - var obj = deserializer.deserialize + var obj = deserializer.deserialize(static_type) if deserializer.errors.not_empty then print_error deserializer.errors.join("\n") diff --git a/src/nitrestful.nit b/src/nitrestful.nit index cf590ce..2303974 100644 --- a/src/nitrestful.nit +++ b/src/nitrestful.nit @@ -131,7 +131,7 @@ redef class MType else # Deserialize everything else template.add """ - var out_{{{arg_name}}} = deserialize_arg(in_{{{arg_name}}}) + var out_{{{arg_name}}} = deserialize_arg(in_{{{arg_name}}}, "{{{self.name}}}") """ end end @@ -263,7 +263,11 @@ redef class {{{mclass}}} """ var mtype = param.mtype - mtype.gen_arg_convert(t, param.name) + var bound_mtype = mclassdef.bound_mtype + var resolved_mtype = mtype.resolve_for(bound_mtype, bound_mtype, mclassdef.mmodule, true) + var resolved_type_name = resolved_mtype.name + + resolved_mtype.gen_arg_convert(t, param.name) var arg = "out_{param.name}" args.add arg -- 1.7.9.5