*: update redefs of `to_json`
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 12 Sep 2016 13:25:38 +0000 (09:25 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 16 Sep 2016 16:17:50 +0000 (12:17 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

17 files changed:
contrib/neo_doxygen/src/model/descriptions.nit
contrib/neo_doxygen/src/model/location.nit
contrib/shibuqam/examples/shibuqamoauth.nit
lib/github/api.nit
lib/github/events.nit
lib/github/github_curl.nit
lib/json/string_parser.nit
lib/neo4j/error.nit
lib/neo4j/graph/json_graph_store.nit
lib/popcorn/pop_repos.nit
lib/popcorn/pop_validation.nit
src/doc/doc_phases/doc_indexing.nit
src/model/model_json.nit
src/web/api_catalog.nit
src/web/api_feedback.nit
src/web/api_metrics.nit
src/web/web_base.nit

index 1f504ef..5a27553 100644 (file)
@@ -106,8 +106,8 @@ class Documentation
        # Is the documentation empty?
        fun is_empty: Bool do return content.is_empty
 
-       redef fun to_json do return content.to_json
-       redef fun append_json(b) do content.append_json(b)
+       redef fun serialize_to(v) do content.serialize_to v
+       redef fun accept_json_serializer(v) do content.serialize_to v
 end
 
 # A `Jsonable` array of strings.
index b78a2ef..a0a183b 100644 (file)
@@ -42,5 +42,6 @@ class Location
                return "{file_part}{line_start},{column_start}--{line_end},{column_end}"
        end
 
-       redef fun to_json do return to_s.to_json
+       redef fun serialize_to(v) do to_s.serialize_to v
+       redef fun accept_json_serializer(v) do to_s.serialize_to v
 end
index 2a52be9..4645eca 100644 (file)
@@ -304,7 +304,6 @@ end
 
 redef class User
        super Jsonable
-       redef fun to_json do return serialize_to_json(plain=true)
 end
 
 # Information about an authenticated used stored on the server to be given to the client.
index 7c85422..e42faf5 100644 (file)
@@ -512,8 +512,6 @@ abstract class GithubEntity
 
        # Github page url.
        var html_url: nullable String is writable
-
-       redef fun to_json do return serialize_to_json
 end
 
 # A Github user
@@ -1062,8 +1060,6 @@ end
 redef class ISODate
        super Jsonable
        serialize
-
-       redef fun to_json do return serialize_to_json
 end
 
 # JsonDeserializer specific for Github objects.
index 2dc0af7..b8c004a 100644 (file)
@@ -33,8 +33,6 @@ class GithubEvent
 
        # Repo where this event occured.
        var repo: Repo is writable
-
-       redef fun to_json do return serialize_to_json
 end
 
 # Triggered when a commit comment is created.
index b5874f3..05761b1 100644 (file)
@@ -127,9 +127,7 @@ class GithubError
                json["message"] = message.to_json
        end
 
-       redef fun to_json do
-               return json.to_json
-       end
+       redef fun serialize_to(v) do json.serialize_to v
 
        redef fun to_s do return "[{name}] {super}"
 end
index 51d302e..19c8fd1 100644 (file)
@@ -344,21 +344,8 @@ redef class Text
 end
 
 redef class JsonParseError
+       serialize
 
        # Location of the error in source
        var location: nullable Location = null
-
-       # Get the JSON representation of `self`.
-       #
-       # ~~~
-       # var err = new JsonParseError("foo", new Position(1, 2, 3, 4, 5, 6))
-       # assert err.to_json == "Parsing error: foo"
-       # ~~~
-       redef fun to_json do
-               var l = location
-               var m = message
-               return if l == null then "Parsing error: {m}" else "Parsing error at {l}: {m}"
-       end
-
-       redef fun to_s do return to_json
 end
index f9df000..d568f45 100644 (file)
@@ -20,15 +20,12 @@ import json::static
 class NeoError
        super Error
        super Jsonable
+       serialize
 
        # The name of the error.
        #
        # Used to programmatically distinguish this kind of error from others.
-       var name: String
-
-       redef fun to_json do
-               return "\{\"error\":{name.to_json},\"message\":{message.to_json}\}"
-       end
+       var name: String is serialize_as "error"
 
        redef fun to_s do return "[{name}] {super}"
 end
index 618a1d3..d924bd9 100644 (file)
@@ -191,35 +191,25 @@ redef class NeoGraph
                end
        end
 
-       redef fun to_json do return to_json_by_append
-
-       # Append the JSON representation of `self` to the specified buffer.
-       #
-       # For a description of the format, see `JsonGraphStore`.
-       #
-       # SEE: `to_json`
-       redef fun append_json(b) do
-               b.append "\{\"nodes\":["
-               append_entities_json(nodes, b)
-               b.append "],\"edges\":["
-               append_entities_json(edges, b)
-               b.append "]\}"
+       redef fun accept_json_serializer(v) do
+               v.stream.write "\{\"nodes\":["
+               append_entities_json(nodes, v)
+               v.stream.write "],\"edges\":["
+               append_entities_json(edges, v)
+               v.stream.write "]\}"
        end
 
        # Encode `self` in JSON.
        #
        # For a description of the format, see `JsonGraphStore`.
-       #
-       # SEE: `append_json`
-       private fun append_entities_json(entities: Collection[NeoEntity],
-                       b: Buffer) do
+       private fun append_entities_json(entities: Collection[NeoEntity], v: JsonSerializer) do
                var i = entities.iterator
                if i.is_ok then
-                       i.item.append_json_for(self, b)
+                       i.item.append_json_for(self, v)
                        i.next
                        for entity in i do
-                               b.add ','
-                               entity.append_json_for(self, b)
+                               v.stream.write ","
+                               entity.append_json_for(self, v)
                        end
                end
        end
@@ -233,7 +223,7 @@ end
 redef class NeoEntity
 
        # Append the JSON representation of the entity to the specified buffer.
-       fun append_json_for(graph: NeoGraph, buffer: Buffer) is abstract
+       fun append_json_for(graph: NeoGraph, v: JsonSerializer) is abstract
 end
 
 # Make `NeoNode` `Jsonable`.
@@ -273,32 +263,27 @@ redef class NeoNode
                properties.add_all(json_properties)
        end
 
-       redef fun to_json do return to_json_by_append
-
-       # Append the JSON representation of the node to the specified buffer.
-       #
-       # SEE: `JsonGraph`
-       redef fun append_json(b) do
-               b.append "\{\"labels\":["
+       redef fun accept_json_serializer(v) do
+               v.stream.write "\{\"labels\":["
                var i = labels.iterator
                if i.is_ok then
-                       i.item.append_json(b)
+                       i.item.serialize_to v
                        i.next
                        for lab in i do
-                               b.add ','
-                               lab.append_json(b)
+                               v.stream.write ","
+                               lab.serialize_to v
                        end
                end
-               b.append "],\"properties\":"
-               properties.append_json(b)
-               b.add '}'
+               v.stream.write "],\"properties\":"
+               properties.serialize_to v
+               v.stream.write "}"
        end
 
        redef fun to_s do return to_json
 
        # Append the JSON representation of the node to the specified buffer.
-       redef fun append_json_for(graph, buffer) do
-               append_json(buffer)
+       redef fun append_json_for(graph, v) do
+               accept_json_serializer v
        end
 end
 
@@ -307,15 +292,15 @@ redef class NeoEdge
        # Append the JSON representation of the relationship to the specified buffer.
        #
        # Use the IDs specfied by `graph.nodes`.
-       redef fun append_json_for(graph, buffer) do
-               buffer.append "\{\"type\":"
-               rel_type.as(not null).append_json(buffer)
-               buffer.append ",\"properties\":"
-               properties.append_json(buffer)
-               buffer.append ",\"from\":"
-               graph.nodes.id_of(from).append_json(buffer)
-               buffer.append ",\"to\":"
-               graph.nodes.id_of(to).append_json(buffer)
-               buffer.append "}"
+       redef fun append_json_for(graph, v) do
+               v.stream.write "\{\"type\":"
+               rel_type.as(not null).serialize_to(v)
+               v.stream.write ",\"properties\":"
+               properties.serialize_to(v)
+               v.stream.write ",\"from\":"
+               graph.nodes.id_of(from).serialize_to(v)
+               v.stream.write ",\"to\":"
+               graph.nodes.id_of(to).serialize_to(v)
+               v.stream.write "}"
        end
 end
index 4c3ea14..0a6bd37 100644 (file)
@@ -54,7 +54,6 @@
 #      redef fun to_s do return title
 #      redef fun ==(o) do return o isa SELF and id == o.id
 #      redef fun hash do return id.hash
-#      redef fun to_json do return serialize_to_json
 # end
 #
 # # We then need to subclass the `MongoRepository` to provide Book specific services.
@@ -436,7 +435,6 @@ abstract class RepoObject
 
        redef fun hash do return id.hash
        redef fun to_s do return id
-       redef fun to_json do return serialize_to_json
 end
 
 # JsonObject can be used as a `RepositoryQuery`.
index 386bb24..7dd529d 100644 (file)
@@ -152,7 +152,7 @@ class ValidationResult
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 
        # Returns the validation result as a pretty formated string
        fun to_pretty_string: String do
index d532d9c..5a2a336 100644 (file)
@@ -67,7 +67,7 @@ class IndexingPhase
                var buffer = new Buffer
                tpl.add buffer
                buffer.append "var nitdocQuickSearchRawList="
-               table.append_json buffer
+               buffer.append table.to_json
                buffer.append ";"
                return tpl
        end
@@ -95,14 +95,11 @@ end
 # A QuickSearch result.
 private class QuickSearchResult
        super Jsonable
+       serialize
 
        # The text of the link.
        var txt: String
 
        # The destination of the link.
        var url: String
-
-       redef fun to_json do
-               return "\{\"txt\":{txt.to_json},\"url\":{url.to_json}\}"
-       end
 end
index 2c5cd04..eaa3feb 100644 (file)
@@ -68,7 +68,7 @@ redef class MEntity
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 
        # Return `self` as a JsonObject with references.
        #
@@ -95,7 +95,7 @@ redef class MDoc
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end
 
 redef class Location
@@ -115,13 +115,13 @@ redef class Location
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end
 
 redef class MVisibility
        super Jsonable
 
-       redef fun to_json do return to_s.to_json
+       redef fun serialize_to(v) do to_s.serialize_to(v)
 end
 
 redef class MPackage
index 30b8757..bd403ad 100644 (file)
@@ -137,12 +137,10 @@ end
 redef class Person
        super Jsonable
 
-       redef fun to_json do
-               var obj = new JsonObject
-               obj["name"] = name
-               obj["email"] = email
-               obj["page"] = page
-               obj["hash"] = (email or else "").md5.to_lower
-               return obj.to_json
+       redef fun core_serialize_to(v) do
+               v.serialize_attribute("name", name)
+               v.serialize_attribute("email", email)
+               v.serialize_attribute("page", page)
+               v.serialize_attribute("hash", (email or else "").md5.to_lower)
        end
 end
index e2bfa9a..a5cacff 100644 (file)
@@ -100,7 +100,7 @@ class MEntityRatings
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end
 
 # Rating value of a MEntity
@@ -130,5 +130,5 @@ class MEntityRating
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end
index bb0147c..8c01c0d 100644 (file)
@@ -162,7 +162,7 @@ redef class MetricSet
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end
 
 redef class Metric
@@ -179,7 +179,7 @@ redef class Metric
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end
 
 redef class IntMetric
index 14bfcca..60f7f2b 100644 (file)
@@ -124,7 +124,7 @@ class APIError
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end
 
 # Fullname representation that can be used to build decorated links
@@ -134,9 +134,10 @@ end
 class Namespace
        super Array[nullable NSEntity]
        super NSEntity
+       serialize
 
        redef fun to_s do return self.join("")
-       redef fun to_json do return (new JsonArray.from(self)).to_json
+       redef fun serialize_to(v) do to_a.serialize_to(v)
 end
 
 # Something that goes in a Namespace
@@ -154,16 +155,17 @@ end
 # an infinite loop.
 class NSRef
        super NSEntity
+       serialize
 
        # The mentity to link to/
        var mentity: MEntity
 
-       redef fun to_json do
+       redef fun serialize_to(v) do
                var obj = new JsonObject
                obj["web_url"] = mentity.web_url
                obj["api_url"] = mentity.api_url
                obj["name"] = mentity.name
-               return obj.to_json
+               obj.serialize_to(v)
        end
 end
 
@@ -364,5 +366,5 @@ redef class POSetElement[E]
                return obj
        end
 
-       redef fun to_json do return json.to_json
+       redef fun serialize_to(v) do json.serialize_to(v)
 end