@@ -27,42 +27,33 @@ feature -- Access
2727feature -- Conversion
2828
2929 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
3430 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?
4831 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
5033 Result .set_name (l_name )
5134 end
52- if l_prompt /= Void then
35+ if attached { STRING_ 32 } json_to_object ( j . item ( prompt_key ), Void ) as l_prompt then
5336 Result .set_prompt (l_prompt )
5437 end
55- if l_value /= Void then
38+ if attached { STRING_ 32 } json_to_object ( j . item ( value_key ), Void ) as l_value then
5639 Result .set_value (l_value )
5740 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?
5845 end
5946
6047 to_json (o : like object ): JSON_OBJECT
6148 do
6249 create Result .make
63- Result .put (json .value (o .prompt ), prompt_key )
6450 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
6657 end
6758
6859feature {NONE } -- Implementation
0 commit comments