22eaf87b4535e8f7bc0a72ae104360a664ba28ea
[nit.git] / tests / test_json_deserialization_safe.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import json
16
17 class MyClass
18 serialize
19
20 var other: MyClass
21
22 type C: MyClass
23 var next: C
24 end
25
26 class DangerSup
27 serialize
28
29 var dangerous_setter: String
30 end
31
32 class DangerSub
33 super DangerSup
34 serialize
35
36 redef fun dangerous_setter=(val)
37 do
38 print "DANGER '{val}'"
39 super
40 end
41 end
42
43 var json_with_metadata = """{
44 "__class": "MyClass",
45 "other": {"__class": "DangerSub", "dangerous_setter": "My text 1"},
46 "next": {"__class": "DangerSub", "dangerous_setter": "My text 2"}
47 }"""
48
49 var deserializer = new JsonDeserializer(json_with_metadata)
50 #alt1#deserializer.check_subtypes = false
51 deserializer.deserialize
52 print deserializer.errors.join("\n")