1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Support module for the `nitrestful` tool and the `restful` annotation
16 module restful
is new_annotation
(restful
)
19 import json
::serialization
21 # Action with `restful` methods
25 redef fun answer
(request
, truncated_uri
) do return new HttpResponse(400)
27 # Service to deserialize arguments from JSON
29 # Accepts `nullable String` for convenience, but returns `null` when `val == null`.
31 # This method is called by the code generated by `nitrestful`.
32 # It can be specialized to customize its behavior.
33 protected fun deserialize_arg
(val
: nullable String): nullable Object
35 if val
== null then return null
37 var deserializer
= new JsonDeserializer(val
)
38 if deserializer
.errors
.not_empty
then
39 print_error deserializer
.errors
.join
("\n")
43 return deserializer
.deserialize