# assert doc.to_json == "[]"
# ~~~
class Documentation
- super Jsonable
+ super Serializable
private var content = new JsonStringArray
private var has_brief_description: Bool = false
redef fun accept_json_serializer(v) do content.serialize_to v
end
-# A `Jsonable` array of strings.
+# A `Serializable` array of strings.
private class JsonStringArray
super JsonSequenceRead[String]
super Array[String]
# A location inside a source file.
class Location
- super Jsonable
+ super Serializable
# The file’s path.
var path: nullable String = null is writable
end
redef class User
- super Jsonable
+ super Serializable
end
# Information about an authenticated used stored on the server to be given to the client.
# assert err isa GithubError
# assert err.name == "GithubAPIError"
# assert err.message == "Not Found"
- fun get(path: String): nullable Jsonable do
+ fun get(path: String): nullable Serializable do
path = sanitize_uri(path)
var res = ghcurl.get_and_parse("{api_url}{path}")
if res isa Error then
#
# Mainly a Nit wrapper around a JSON objet.
abstract class GithubEntity
- super Jsonable
serialize
# Github page url.
# Make ISO Datew serilizable
redef class ISODate
- super Jsonable
serialize
end
# Github event stub.
class GithubEvent
- super Jsonable
serialize
# Event ID from Github.
# Get the requested URI, and check the HTTP response. Then convert to JSON
# and check for Github errors.
- fun get_and_check(uri: String): nullable Jsonable
+ fun get_and_check(uri: String): nullable Serializable
do
var request = new CurlHTTPRequest(uri)
request.user_agent = user_agent
# Then convert to JSON and check for Github errors.
# Unlike `get_and_check`, error do not trigger an abort but
# are reported as `GithubError`.
- fun get_and_parse(uri: String): nullable Jsonable
+ fun get_and_parse(uri: String): nullable Serializable
do
var request = new CurlHTTPRequest(uri)
request.user_agent = user_agent
# Check the `json` value to find them.
class GithubError
super Error
- super Jsonable
+ super Serializable
# The name of the error.
var name: String
private import json_parser
private import json_lexer
-# Something that can be translated to JSON.
-interface Jsonable
- super Serializable
-end
-
redef class Text
- super Jsonable
# Removes JSON-escaping if necessary in a JSON string
#
# var bad = "\{foo: \"bar\"\}".parse_json
# assert bad isa JsonParseError
# assert bad.position.col_start == 2
- fun parse_json: nullable Jsonable do
+ fun parse_json: nullable Serializable do
var lexer = new Lexer_json(to_s)
var parser = new Parser_json
var tokens = lexer.lex
end
end
-redef class Int
- super Jsonable
-end
-
-redef class Float
- super Jsonable
-end
-
-redef class Bool
- super Jsonable
-end
-
# A map that can be translated into a JSON object.
-interface JsonMapRead[K: String, V: nullable Jsonable]
+interface JsonMapRead[K: String, V: nullable Serializable]
super MapRead[K, V]
- super Jsonable
+ super Serializable
end
# A JSON Object.
class JsonObject
- super JsonMapRead[String, nullable Jsonable]
- super HashMap[String, nullable Jsonable]
+ super JsonMapRead[String, nullable Serializable]
+ super HashMap[String, nullable Serializable]
end
# A sequence that can be translated into a JSON array.
-class JsonSequenceRead[E: nullable Jsonable]
- super Jsonable
+class JsonSequenceRead[E: nullable Serializable]
+ super Serializable
super SequenceRead[E]
end
# A JSON array.
class JsonArray
- super JsonSequenceRead[nullable Jsonable]
- super Array[nullable Jsonable]
-end
-
-redef class JsonParseError
- super Jsonable
-end
-
-redef class Position
- super Jsonable
+ super JsonSequenceRead[nullable Serializable]
+ super Array[nullable Serializable]
end
################################################################################
redef class Nvalue
# The represented value.
- private fun to_nit_object: nullable Jsonable is abstract
+ private fun to_nit_object: nullable Serializable is abstract
end
redef class Nvalue_number
private fun name: String do return n_string.to_nit_string
# The represented value.
- private fun value: nullable Jsonable do return n_value.to_nit_object
+ private fun value: nullable Serializable do return n_value.to_nit_object
end
redef class Nvalue_array
#
# Only `JsonObject` and `JsonArray` are allowed in a json file.
# Use `store_object` or `store_array` instead.
- private fun store_json(key: String, json: Jsonable) do
+ private fun store_json(key: String, json: Serializable) do
var path = "{store_dir}/{key}.json".simplify_path
path.dirname.mkdir
var file = new FileWriter.open(path)
# Load a JsonObject associated to `key` from store.
#
# Ensure `has_data(key)`
- private fun load_json(key: String): nullable Jsonable do
+ private fun load_json(key: String): nullable Serializable do
assert has_key(key)
var path = "{store_dir}/{key}.json".simplify_path
var file = new FileReader.open(path)
# var p = new JSONStringParser("""{"numbers": [1,23,3], "string": "string"}""")
# assert p.parse_entity isa JsonObject
# ~~~
- fun parse_entity: nullable Jsonable do
+ fun parse_entity: nullable Serializable do
var srclen = len
ignore_whitespaces
if pos >= srclen then return make_parse_error("Empty JSON")
end
# Parses a JSON Array
- fun parse_json_array: Jsonable do
+ fun parse_json_array: Serializable do
var max = len
if pos >= max then return make_parse_error("Incomplete JSON array")
var arr = new JsonArray
end
# Parses a JSON Object
- fun parse_json_object: Jsonable do
+ fun parse_json_object: Serializable do
var max = len
if pos >= max then return make_parse_error("Incomplete JSON object")
var obj = new JsonObject
end
# Parses an Int or Float
- fun parse_json_number: Jsonable do
+ fun parse_json_number: Serializable do
var max = len
var p = pos
var c = src[p]
private var parse_str_buf = new FlatBuffer
# Parses and returns a Nit string from a JSON String
- fun parse_json_string: Jsonable do
+ fun parse_json_string: Serializable do
var src = src
var ln = src.length
var p = pos
# ~~~json
# {field: {$<name>: <value>} }
# ~~~
- fun op(name: String, field: nullable String, value: nullable Jsonable): MongoMatch do
+ fun op(name: String, field: nullable String, value: nullable Serializable): MongoMatch do
if field != null then
var q = new JsonObject
q["${name}"] = value
# ~~~json
# {field: {$eq: value} }
# ~~~
- fun eq(field: String, value: nullable Jsonable): MongoMatch do
+ fun eq(field: String, value: nullable Serializable): MongoMatch do
self[field] = value
return self
end
# ~~~json
# {field: {$ne: value} }
# ~~~
- fun ne(field: String, value: nullable Jsonable): MongoMatch do
+ fun ne(field: String, value: nullable Serializable): MongoMatch do
op("ne", field, value)
return self
end
# ~~~json
# {field: {$gt: value} }
# ~~~
- fun gt(field: String, value: nullable Jsonable): MongoMatch do
+ fun gt(field: String, value: nullable Serializable): MongoMatch do
op("gt", field, value)
return self
end
# ~~~json
# {field: {$gte: value} }
# ~~~
- fun gte(field: String, value: nullable Jsonable): MongoMatch do
+ fun gte(field: String, value: nullable Serializable): MongoMatch do
op("gte", field, value)
return self
end
# ~~~json
# {field: {$lt: value} }
# ~~~
- fun lt(field: String, value: nullable Jsonable): MongoMatch do
+ fun lt(field: String, value: nullable Serializable): MongoMatch do
op("lt", field, value)
return self
end
# ~~~json
# {field: {$lte: value} }
# ~~~
- fun lte(field: String, value: nullable Jsonable): MongoMatch do
+ fun lte(field: String, value: nullable Serializable): MongoMatch do
op("lte", field, value)
return self
end
#
# `$in` selects the documents where the value of a field equals any value
# in the specified array.
- fun is_in(field: String, values: Array[nullable Jsonable]): MongoMatch do
+ fun is_in(field: String, values: Array[nullable Serializable]): MongoMatch do
op("in", field, new JsonArray.from(values))
return self
end
# `$nin` selects the documents where:
# * the field value is not in the specified array or
# * the field does not exist.
- fun is_nin(field: String, values: Array[nullable Jsonable]): MongoMatch do
+ fun is_nin(field: String, values: Array[nullable Serializable]): MongoMatch do
op("nin", field, new JsonArray.from(values))
return self
end
# ~~~json
# { field: { $or: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] } }
# ~~~
- fun lor(field: nullable String, expressions: Array[Jsonable]): MongoMatch do
+ fun lor(field: nullable String, expressions: Array[Serializable]): MongoMatch do
op("or", field, new JsonArray.from(expressions))
return self
end
# ~~~json
# { field: { $and: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] } }
# ~~~
- fun land(field: nullable String, expressions: Array[Jsonable]): MongoMatch do
+ fun land(field: nullable String, expressions: Array[Serializable]): MongoMatch do
op("and", field, new JsonArray.from(expressions))
return self
end
# ~~~json
# { field: { $not: { <expression> } } }
# ~~~
- fun lnot(field: nullable String, expression: Jsonable): MongoMatch do
+ fun lnot(field: nullable String, expression: Serializable): MongoMatch do
op("not", field, expression)
return self
end
# ~~~json
# { field: { $nor: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] } }
# ~~~
- fun lnor(field: nullable String, expressions: Array[Jsonable]): MongoMatch do
+ fun lnor(field: nullable String, expressions: Array[Serializable]): MongoMatch do
op("nor", field, new JsonArray.from(expressions))
return self
end
# ~~~json
# { field: { $all: [ <value1>, <value2>, ... ] } }
# ~~~
- fun all(field: nullable String, values: Array[Jsonable]): MongoMatch do
+ fun all(field: nullable String, values: Array[Serializable]): MongoMatch do
op("all", field, new JsonArray.from(values))
return self
end
# ~~~json
# { field: { $elemMatch: <query> } }
# ~~~
- fun elem_match(field: nullable String, query: Jsonable): MongoMatch do
+ fun elem_match(field: nullable String, query: Serializable): MongoMatch do
op("elemMatch", field, query)
return self
end
# ~~~json
# { $<stage>: <json> }
# ~~~
- fun add_stage(stage: String, json: Jsonable): MongoPipeline do
+ fun add_stage(stage: String, json: Serializable): MongoPipeline do
var obj = new JsonObject
obj["${stage}"] = json
add obj
# ~~~json
# <field>: { <accumulator> : <expression> }
# ~~~
- private fun acc(name: String, field: String, expression: nullable Jsonable): MongoGroup do
+ private fun acc(name: String, field: String, expression: nullable Serializable): MongoGroup do
var q = new JsonObject
q["${name}"] = expression
self[field] = q
# ~~~
#
# `$sum` ignores non-numeric values.
- fun sum(field: String, expression: Jsonable): MongoGroup do
+ fun sum(field: String, expression: Serializable): MongoGroup do
return acc("sum", field, expression)
end
# ~~~
#
# `$avg` ignores non-numeric values.
- fun avg(field: String, expression: Jsonable): MongoGroup do
+ fun avg(field: String, expression: Serializable): MongoGroup do
return acc("avg", field, expression)
end
#
# `$max` compares both value and type, using the specified BSON comparison
# order for values of different types.
- fun max(field: String, expression: Jsonable): MongoGroup do
+ fun max(field: String, expression: Serializable): MongoGroup do
return acc("max", field, expression)
end
#
# `$min` compares both value and type, using the specified BSON comparison
# order for values of different types.
- fun min(field: String, expression: Jsonable): MongoGroup do
+ fun min(field: String, expression: Serializable): MongoGroup do
return acc("min", field, expression)
end
# document in a group of documents that share the same group by key.
#
# Only meaningful when documents are in a defined order.
- fun first(field: String, expression: Jsonable): MongoGroup do
+ fun first(field: String, expression: Serializable): MongoGroup do
return acc("first", field, expression)
end
# document in a group of documents that share the same group by key.
#
# Only meaningful when documents are in a defined order.
- fun last(field: String, expression: Jsonable): MongoGroup do
+ fun last(field: String, expression: Serializable): MongoGroup do
return acc("last", field, expression)
end
#
# Returns an array of all values that result from applying an expression to
# each document in a group of documents that share the same group by key.
- fun push(field: String, expr: Jsonable): MongoGroup do
+ fun push(field: String, expr: Serializable): MongoGroup do
return acc("push", field, expr)
end
# group by key.
#
# Order of the elements in the output array is unspecified.
- fun addToSet(field: String, expr: Jsonable): MongoGroup do
+ fun addToSet(field: String, expr: Serializable): MongoGroup do
return acc("addToSet", field, expr)
end
end
class JsonPOST
super JsonCurlRequest
- var json_data: nullable Jsonable = null is writable
+ var json_data: nullable Serializable = null is writable
redef fun init_headers do
super
class JsonPUT
super JsonCurlRequest
- var json_data: nullable Jsonable = null is writable
+ var json_data: nullable Serializable = null is writable
redef fun init_headers do
super
return null
end
end
-
# assert error.to_json == """{"message":"ErrorMessage","cause":null,"error":"ErrorName"}"""
class NeoError
super Error
- super Jsonable
serialize
# The name of the error.
super SimpleCollection[NeoNode]
# The type of the local IDs.
- type ID_TYPE: Jsonable
+ type ID_TYPE: Serializable
# The property of the nodes that hold the local ID.
var id_property: String
end
redef class NeoGraph
- super Jsonable
+ super Serializable
# Retrieve the graph from the specified JSON document.
#
redef class NeoNodeCollection
# Convert the specified JSON value into a local ID.
- fun id_from_jsonable(id: nullable Jsonable): ID_TYPE do return id.as(ID_TYPE)
+ fun id_from_jsonable(id: nullable Serializable): ID_TYPE do return id.as(ID_TYPE)
end
redef class NeoEntity
fun append_json_for(graph: NeoGraph, v: JsonSerializer) is abstract
end
-# Make `NeoNode` `Jsonable`.
+# Make `NeoNode` `Serializable`.
redef class NeoNode
- super Jsonable
+ super Serializable
# Retrieve the node from the specified JSON value.
#
self.cypher_url = root["cypher"].to_s
end
- fun service_root: Jsonable do return get(base_url / "db/data")
+ fun service_root: Serializable do return get(base_url / "db/data")
# Is the connection with the Neo4j server ok?
fun is_ok: Bool do return service_root isa JsonObject
# Perform a `CypherQuery`
# see: CypherQuery
- fun cypher(query: CypherQuery): Jsonable do
+ fun cypher(query: CypherQuery): Serializable do
return post("{cypher_url}", query.to_rest)
end
# GET JSON data from `url`
- fun get(url: String): Jsonable do
+ fun get(url: String): Serializable do
var request = new JsonGET(url)
var response = request.execute
return parse_response(response)
end
# POST `params` to `url`
- fun post(url: String, params: Jsonable): Jsonable do
+ fun post(url: String, params: Serializable): Serializable do
var request = new JsonPOST(url)
request.json_data = params
var response = request.execute
end
# PUT `params` at `url`
- fun put(url: String, params: Jsonable): Jsonable do
+ fun put(url: String, params: Serializable): Serializable do
var request = new JsonPUT(url)
request.json_data = params
var response = request.execute
end
# DELETE `url`
- fun delete(url: String): Jsonable do
+ fun delete(url: String): Serializable do
var request = new JsonDELETE(url)
var response = request.execute
return parse_response(response)
end
# Parse the cURL `response` as a JSON string
- private fun parse_response(response: CurlResponse): Jsonable do
+ private fun parse_response(response: CurlResponse): Serializable do
if response isa CurlResponseSuccess then
var str = response.body_str
if str.is_empty then return new JsonObject
end
# Get the entity property at `key`
- fun [](key: String): nullable Jsonable do
+ fun [](key: String): nullable Serializable do
if not properties.has_key(key) then return null
return properties[key]
end
# Set the entity property `value` at `key`
- fun []=(key: String, value: nullable Jsonable) do properties[key] = value
+ fun []=(key: String, value: nullable Serializable) do properties[key] = value
# Is the property `key` set?
fun has_key(key: String): Bool do return properties.has_key(key)
end
# Associate data from response in original nodes and edges
- private fun finalize_batch(response: Jsonable): List[NeoError] do
+ private fun finalize_batch(response: Serializable): List[NeoError] do
var errors = new List[NeoError]
if not response isa JsonArray then
errors.add(new NeoError("Unexpected batch response format.", "Neo4jError"))
# Job service target: `/node`, `/labels` etc...
var to: String
# Body to send with the job service request
- var body: nullable Jsonable = null
+ var body: nullable Serializable = null
# JSON formated job
fun to_rest: JsonObject do
# # Serializable book representation.
# class Book
# serialize
-# super Jsonable
#
# # Book uniq ID
# var id: String = (new MongoObjectId).id is serialize_as "_id"
# end
# ~~~
abstract class RepoObject
- super Jsonable
serialize
# `self` unique id.
#
# # Serializable book representation.
# class Book
-# super Jsonable
+# super Serializable
#
# # Book ISBN
# var isbn: String
#
# See `HttpResponse::json_error`.
class ValidationResult
- super Jsonable
+ super Serializable
# Object parsed during validation
#
return validate_json(json)
end
- # Validate a Jsonable input
- fun validate_json(json: Jsonable): Bool do
+ # Validate a Serializable input
+ fun validate_json(json: Serializable): Bool do
if not json isa JsonObject then
validation.add_error("document", "Expected JsonObject got `{json.class_name}`")
return false
return validate_json(json)
end
- # Validate a Jsonable input
- fun validate_json(json: Jsonable): Bool do
+ # Validate a Serializable input
+ fun validate_json(json: Serializable): Bool do
if not json isa JsonArray then
validation.add_error("document", "Expected JsonArray got `{json.class_name}`")
return false
# A QuickSearch result.
private class QuickSearchResult
- super Jsonable
serialize
# The text of the link.
end
# Recursively collect all string values in a json value associated to a given key.
-fun search_json(json: nullable Jsonable, key: String, result: nullable Array[String]): Array[String]
+fun search_json(json: nullable Serializable, key: String, result: nullable Array[String]): Array[String]
do
if result == null then result = new Array[String]
if json isa JsonObject then
# See the License for the specific language governing permissions and
# limitations under the License.
-# Make model entities Jsonable.
+# Make model entities Serializable.
#
# To avoid cycles, every reference from a MEntity to another is replaced by a
# MEntityRef.
end
redef class MEntity
- super Jsonable
serialize
redef fun core_serialize_to(v) do
end
redef class MDoc
- super Jsonable
serialize
redef fun core_serialize_to(v) do
end
redef class Location
- super Jsonable
serialize
redef fun core_serialize_to(v) do
end
redef class Person
- super Jsonable
+ super Serializable
redef fun core_serialize_to(v) do
v.serialize_attribute("name", name)
end
redef class MetricSet
- super Jsonable
+ super Serializable
redef fun core_serialize_to(v) do
for metric in metrics do
end
redef class Metric
- super Jsonable
+ super Serializable
redef fun core_serialize_to(v) do
v.serialize_attribute("name", name)
end
private class MetricEntry
- super Jsonable
+ super Serializable
var mentity: MEntity
var value: Object
#
# Can be serialized to json.
class APIError
- super Jsonable
serialize
# Reponse status
# * a `NSToken` for tokens like `::`, `>` and `$`
# * a `MSRef` for references to mentities
interface NSEntity
- super Jsonable
+ super Serializable
end
# A reference to a MEntity that can be rendered as a link.
end
redef class POSetElement[E]
- super Jsonable
+ super Serializable
redef fun serialize_to(v) do
assert self isa POSetElement[MEntity]