Improve converters.
Replace old syntax with new one and improve implementation.
This commit is contained in:
@@ -4,7 +4,8 @@ note
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class JSON_BOOK_CONVERTER
|
||||
class
|
||||
JSON_BOOK_CONVERTER
|
||||
|
||||
inherit
|
||||
JSON_CONVERTER
|
||||
@@ -31,17 +32,14 @@ feature -- Access
|
||||
feature -- Conversion
|
||||
|
||||
from_json (j: like to_json): detachable like object
|
||||
local
|
||||
ucs1, ucs2: detachable STRING_32
|
||||
a: detachable AUTHOR
|
||||
do
|
||||
ucs1 ?= json.object (j.item (title_key), Void)
|
||||
check ucs1 /= Void end
|
||||
ucs2 ?= json.object (j.item (isbn_key), Void)
|
||||
check ucs2 /= Void end
|
||||
a ?= json.object (j.item (author_key), "AUTHOR")
|
||||
check a /= Void end
|
||||
create Result.make (ucs1, a, ucs2)
|
||||
if
|
||||
attached {STRING_32} json.object (j.item (title_key), Void) as l_title and
|
||||
attached {STRING_32} json.object (j.item (isbn_key), Void) as l_isbn and
|
||||
attached {AUTHOR} json.object (j.item (author_key), "AUTHOR") as l_author
|
||||
then
|
||||
create Result.make (l_title, l_author, l_isbn)
|
||||
end
|
||||
end
|
||||
|
||||
to_json (o: like object): JSON_OBJECT
|
||||
@@ -52,19 +50,22 @@ feature -- Conversion
|
||||
Result.put (json.value (o.author), author_key)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
title_key: JSON_STRING
|
||||
-- Book's title label.
|
||||
once
|
||||
create Result.make_json ("title")
|
||||
end
|
||||
|
||||
isbn_key: JSON_STRING
|
||||
-- Book ISBN label.
|
||||
once
|
||||
create Result.make_json ("isbn")
|
||||
end
|
||||
|
||||
author_key: JSON_STRING
|
||||
-- Author label.
|
||||
once
|
||||
create Result.make_json ("author")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user