@@ -27,42 +27,33 @@ feature -- Access
27
27
feature -- Conversion
28
28
29
29
from_json (j : like to_json ): detachable like object
30
- local
31
- l_name : detachable STRING_ 32
32
- l_prompt : detachable STRING_ 32
33
- l_value : detachable STRING_ 32
34
30
do
35
- if attached {STRING_ 32 } json_to_object (j .item (name_key ), Void ) as l_ucs then
36
- l_name := l_ucs
37
- end
38
- if attached {STRING_ 32 } json_to_object (j .item (prompt_key ), Void ) as l_ucs then
39
- l_prompt := l_ucs
40
- end
41
- if attached {STRING_ 32 } json_to_object (j .item (value_key ), Void ) as l_ucs then
42
- l_value := l_ucs
43
- end
44
- -- |TODO improve this code
45
- -- |is there a better way to write this?
46
- -- |is a good idea create the Result object at the first line and then set the value
47
- -- |if it is attached?
48
31
create Result .make
49
- if l_name /= Void then
32
+ if attached { STRING_ 32 } json_to_object ( j . item ( name_key ), Void ) as l_name then
50
33
Result .set_name (l_name )
51
34
end
52
- if l_prompt /= Void then
35
+ if attached { STRING_ 32 } json_to_object ( j . item ( prompt_key ), Void ) as l_prompt then
53
36
Result .set_prompt (l_prompt )
54
37
end
55
- if l_value /= Void then
38
+ if attached { STRING_ 32 } json_to_object ( j . item ( value_key ), Void ) as l_value then
56
39
Result .set_value (l_value )
57
40
end
41
+ -- |TODO improve this code
42
+ -- |is there a better way to write this?
43
+ -- |is a good idea create the Result object at the first line and then set the value
44
+ -- |if it is attached?
58
45
end
59
46
60
47
to_json (o : like object ): JSON_OBJECT
61
48
do
62
49
create Result .make
63
- Result .put (json .value (o .prompt ), prompt_key )
64
50
Result .put (json .value (o .name ), name_key )
65
- Result .put (json .value (o .value ), value_key )
51
+ if attached o .prompt as o_prompt then
52
+ Result .put (json .value (o_prompt ), prompt_key )
53
+ end
54
+ if attached o .value as o_value then
55
+ Result .put (json .value (o_value ), value_key )
56
+ end
66
57
end
67
58
68
59
feature {NONE } -- Implementation
0 commit comments