Conflicts:
	draft/library/gobo/shared_gobo_ejson.e
	draft/library/kernel/converters/json_converter.e
	draft/library/kernel/converters/json_hash_table_converter.e
	draft/library/kernel/converters/json_linked_list_converter.e
	draft/library/kernel/ejson.e
	draft/library/kernel/shared_ejson.e
	draft/test/autotest/test_suite/json_author_converter.e
	draft/test/autotest/test_suite/json_book_collection_converter.e
	draft/test/autotest/test_suite/json_book_converter.e
	draft/test/autotest/test_suite/test_json_core.e
This commit is contained in:
Jocelyn Fiat
2012-08-24 02:40:54 -07:00
13 changed files with 329 additions and 80 deletions

View File

@@ -0,0 +1,30 @@
note
description: "A JSON converter for ARRAYED_LIST [ANY]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
class JSON_ARRAYED_LIST_CONVERTER
inherit
JSON_LIST_CONVERTER
redefine
object
end
create
make
feature -- Access
object: ARRAYED_LIST [detachable ANY]
feature {NONE} -- Factory
new_object (nb: INTEGER): like object
do
create Result.make (nb)
end
end -- class JSON_ARRAYED_LIST_CONVERTER

View File

@@ -1,8 +1,8 @@
note
description: "A JSON converter"
author: "Paul Cohen"
date: "$Date: $"
revision: "$Revision: $"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
deferred class JSON_CONVERTER
@@ -19,7 +19,7 @@ feature -- Access
feature -- Conversion
from_json (j: attached like to_json): detachable like object
from_json (j: attached like to_json): detachable like object
-- Convert from JSON value.
-- Returns Void if unable to convert
deferred

View File

@@ -1,8 +1,8 @@
note
description: "A JSON converter for HASH_TABLE [ANY, HASHABLE]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
class JSON_HASH_TABLE_CONVERTER
@@ -26,7 +26,7 @@ feature -- Access
feature -- Conversion
from_json (j: attached like to_json): like object
from_json (j: attached like to_json): like object
local
keys: ARRAY [JSON_STRING]
i: INTEGER
@@ -41,7 +41,7 @@ feature -- Conversion
until
i > keys.count
loop
h ?= json.object (keys [i], void)
h ?= json.object (keys [i], Void)
check h /= Void end
jv := j.item (keys [i])
if jv /= Void then

View File

@@ -1,63 +1,30 @@
note
description: "A JSON converter for LINKED_LIST [ANY]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
description: "A JSON converter for LINKED_LIST [ANY]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
class JSON_LINKED_LIST_CONVERTER
inherit
JSON_CONVERTER
JSON_LIST_CONVERTER
redefine
object
end
create
make
feature {NONE} -- Initialization
make
do
create object.make
end
feature -- Access
object: LINKED_LIST [detachable ANY]
feature -- Conversion
feature {NONE} -- Factory
from_json (j: like to_json): detachable like object
local
i: INTEGER
do
create Result.make
from
i := 1
until
i > j.count
loop
Result.extend (json.object (j [i], Void))
i := i + 1
end
end
to_json (o: like object): JSON_ARRAY
local
c: ITERATION_CURSOR [detachable ANY]
do
create Result.make_array
from
c := o.new_cursor
until
c.after
loop
if attached json.value (c.item) as v then
Result.add (v)
else
check attached_value: False end
end
c.forth
end
end
new_object (nb: INTEGER): like object
do
create Result.make
end
end -- class JSON_LINKED_LIST_CONVERTER

View File

@@ -0,0 +1,74 @@
note
description: "A JSON converter for LIST [ANY]"
author: "Paul Cohen"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
deferred class JSON_LIST_CONVERTER
inherit
JSON_CONVERTER
feature {NONE} -- Initialization
make
do
object := new_object (0)
end
feature -- Access
object: LIST [detachable ANY]
feature {NONE} -- Factory
new_object (nb: INTEGER): like object
deferred
ensure
Result /= Void
end
feature -- Conversion
from_json (j: attached like to_json): detachable like object
local
i: INTEGER
do
Result := new_object (j.count)
from
i := 1
until
i > j.count
loop
Result.extend (json.object (j [i], Void))
i := i + 1
end
end
to_json (o: like object): detachable JSON_ARRAY
local
c: ITERATION_CURSOR [detachable ANY]
jv: detachable JSON_VALUE
failed: BOOLEAN
do
create Result.make_array
from
c := o.new_cursor
until
c.after
loop
jv := json.value (c.item)
if jv /= Void then
Result.add (jv)
else
failed := True
end
c.forth
end
if failed then
Result := Void
end
end
end -- class JSON_ARRAYED_LIST_CONVERTER

View File

@@ -1,8 +1,8 @@
note
description: "Core factory class for creating JSON objects and corresponding Eiffel objects."
author: "Paul Cohen"
date: "$Date: $"
revision: "$Revision: $"
date: "$Date$"
revision: "$Revision$"
file: "$HeadURL: $"
class EJSON
@@ -69,7 +69,7 @@ feature -- Access
elseif attached {STRING_8} an_object as s8 then
create {JSON_STRING} Result.make_json (s8)
elseif attached {STRING_32} an_object as s32 then
create {JSON_STRING} Result.make_json (s32.as_string_8) -- FIXME: need correct convertion/encoding here ...
create {JSON_STRING} Result.make_json_from_string_32 (s32)
end
if Result = Void then
@@ -253,9 +253,9 @@ feature {NONE} -- Implementation (Exceptions)
-- Exception message for failing to convert `a' to a JSON_VALUE.
do
Result := exception_prefix + "Failed to convert Eiffel object to a JSON_VALUE"
if an_object /= Void then
Result := ": " + an_object.generator
end
if an_object /= Void then
Result := ": " + an_object.generator
end
end
feature {NONE} -- Implementation (JSON parser)

View File

@@ -1,14 +1,14 @@
note
description: "[
Shared factory class for creating JSON objects. Maps JSON
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
LINKED_LISTs. Use non-conforming inheritance from this
class to ensure that your classes share the same
JSON_FACTORY instance.
Shared factory class for creating JSON objects. Maps JSON
objects to ELKS HASH_TABLEs and JSON arrays to ELKS
LINKED_LISTs. Use non-conforming inheritance from this
class to ensure that your classes share the same
JSON_FACTORY instance.
]"
author: "Paul Cohen"
date: "$Date: $"
revision: "$Revision: $"
date: "$Date$"
revision: "$Revision: 89185 $"
file: "$HeadURL: $"
class SHARED_EJSON
@@ -17,16 +17,22 @@ feature
json: EJSON
-- A shared EJSON instance with default converters for
-- DS_LINKED_LIST [ANY] and DS_HASH_TABLE [ANY, HASHABLE]
--LINKED_LIST [ANY] and HASH_TABLE [ANY, HASHABLE]
local
jalc: JSON_ARRAYED_LIST_CONVERTER
jllc: JSON_LINKED_LIST_CONVERTER
jhtc: JSON_HASH_TABLE_CONVERTER
once
create Result
create jalc.make
Result.add_converter (jalc)
create jllc.make
Result.add_converter (jllc)
create jhtc.make
Result.add_converter (jhtc)
end
end -- class SHARED_EJSON
end -- class SHARED_EJSON