Merge: JSON: merge 2 services into `serialize_to_json` and isolate from `static`
authorJean Privat <jean@pryen.org>
Tue, 17 May 2016 01:22:48 +0000 (21:22 -0400)
committerJean Privat <jean@pryen.org>
Tue, 17 May 2016 01:22:48 +0000 (21:22 -0400)
commit77f058526bd7daba18af2df4b7c87aa173ce088f
tree118e06f9731bcd65c89e76b30a20fb460ccfc093
parent17543d4946687dee470b1d2f813e29b16a87a90c
parent050fae7bdfdb92a114f88b22fa337aa6f6d000e8
Merge: JSON: merge 2 services into `serialize_to_json` and isolate from `static`

The first goal of this PR is to create a simple but customizable service to write Nit objects to JSON (replacing `to_json_string` and `to_plain_json`). It also clarifies how the serialization of a single object can be customized by refining `accept_json_serializer` which allows the same customization of the existing recursive `to_json` but on any `Serializable` objects.

The second goal is to isolate `json::serialization` from `json::static`. This allows to hide the complexity of `static` to clients of `serialization` and will help to deprecate the `static` writing services. After this PR, `serialization` uses really only one service from `static`, `String::to_json` which escapes strings. While `paser_json` uses the new @R4PaSs implementation. The types of `static` didn't add any useful services in the context of the `JsonDeserializer` (they only have writing services) and added both complexity and dependencies to the module.

All of this would make it easy (if there is still interest) to unify all JSON writing APIs and replace the current `Jsonable::to_json` with a single `Serializable::to_json` using the implementation of the new method `serialize_to_json`. And we can update the existing `redef fun to_json` to `redef fun accept_json_serializer`  writing to a stream instead of a string.

Pull-Request: #2068
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>