nitcorn :: MyAction :: complex_args
complex_args?array=["a","b"]&data={"str":"asdf","more":{"str":"ASDF"}}
Collections and other classes can also be used as parameters,
they will be deserialized from JSON format.
By default, the JSON objects will be parsed as the type of the parameter.
In the example above, the argument passed as data
is deserialized as a MyData
.
However, you can use metadata in the JSON object to deserialize it
as a subclass of MyData
, as in this request where data
is a MyOtherData
:
complex_args?array=["a","b"]&data={"__class":"MyOtherData","str":"asdf","i":1234}
See the json
package documentation for more information on JSON
deserialization and the metadata values.
# Method with two complex parameters answering requests such as
# `complex_args?array=["a","b"]&data={"str":"asdf","more":{"str":"ASDF"}}`
#
# Collections and other classes can also be used as parameters,
# they will be deserialized from JSON format.
# By default, the JSON objects will be parsed as the type of the parameter.
# In the example above, the argument passed as `data` is deserialized as a `MyData`.
# However, you can use metadata in the JSON object to deserialize it
# as a subclass of `MyData`, as in this request where `data` is a `MyOtherData`:
#
# `complex_args?array=["a","b"]&data={"__class":"MyOtherData","str":"asdf","i":1234}`
#
# See the `json` package documentation for more information on JSON
# deserialization and the metadata values.
fun complex_args(array: Array[String], data: MyData): HttpResponse
is restful do
var resp = new HttpResponse(200)
resp.body = "complex_args {array} {data}"
return resp
end
lib/nitcorn/examples/src/restful_annot.nit:68,2--87,4