| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
| |
Drop `SECTION` blurbs.
Use gi-docgen syntax for internal links.
Use summary lines for gi-docgen indices.
Use Markdown syntax for code fragments.
|
|
|
|
|
|
|
|
|
| |
The current iterator API does not guarantee the iteration order, as it's
based off of the hash table iterator. JsonObject, though, can guarantee
the iteration order—we do that for json_object_foreach_member().
Instead of changing the behaviour of json_object_iter_next(), we can add
API to initialize and iterate a JsonObjectIter in insertion order.
|
|\
| |
| |
| |
| |
| |
| | |
Add JsonObject getters with fallback value
Closes #4
See merge request GNOME/json-glib!4
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When using the typed getters for JsonObject, the existing API will
automatically fail if the member requested is not present. This is
generally good practice, because JSON data typically does not have a
schema, and thus is has to be validated "on the go"; a JSON object
member that contains `null`, or `0`, or `false`, is indistinguishable
from a JSON object member that does not exist, so we cannot simply
return a scalar value and be done with it.
We can provide an escape hatch, though, for the crowd writing parsers
for JSON data; by using Python as the model, we can add methods that
take a default value as a parameter, and return it as a fallback value
if the requested object member does not exist, or if it's set to `null`.
|
|/
|
|
|
|
| |
json_node_unref was added after the autoptr macros were written.
This fixes an assertion failure if using autoptr and json_node_ref.
|
|
|
|
|
| |
The json_node_is_immutable() missed an JSON_AVAILABLE_IN_1_2, causing it
not to be exported. Fix this.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Now that these objects can be marked as immutable, it is possible to
calculate and cache hash values for each of them. This allows efficient
hash-based deduplication of large numbers of JSON nodes, as needed by
Walbottle for JSON test vector generation.
To complement the new hash functions, each of JsonNode, JsonValue,
JsonObject and JsonArray also now have an equal() comparison method.
This compares them structurally and recursively, using the definition of
equality from the JSON Schema specification, which seems as good as any
other.
http://json-schema.org/latest/json-schema-core.html#anchor9
https://bugzilla.gnome.org/show_bug.cgi?id=756121
Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add reference counting semantics to JsonNode, in addition to the
existing init/unset and alloc/free semantics.
json_node_free() must only be used with nodes allocated using
json_node_alloc(). json_node_unref() may be used with all nodes (if
correctly paired; it may be paired with json_node_alloc()).
It is not valid to call json_node_free() on a node whose reference count
is not 1.
https://bugzilla.gnome.org/show_bug.cgi?id=756121
|
|
|
|
|
|
|
|
|
|
|
| |
Add an immutable mode to JsonNode, JsonObject, JsonArray and JsonValue.
This is an optional mode which objects enter by calling json_*_seal().
It is a one-way transition, which means that we can build and manipulate
objects as much as desired, before sealing them and enjoying the
benefits of immutable objects: no need to take copies when handling
them, persistent hash values (still to be implemented).
https://bugzilla.gnome.org/show_bug.cgi?id=756121
|
|
|
|
|
|
|
| |
GLib can take advantage of the "cleanup" attribute by using a bunch of
macro magic. This has been slowly been used across various libraries in
the G* stack, so JSON-GLib should provide symbols for the automatic
memory management of its types.
|
|
|
|
|
|
|
|
|
| |
Use padding which resembles the ABI structure of GHashTableIter so that
our struct size is the same as GHashTableIter on all platforms, rather
than just on x86_64. This fixes the static assertion failure on i386 and
armhf.
https://bugzilla.gnome.org/show_bug.cgi?id=757675
|
|
|
|
|
|
|
|
|
|
| |
This is a stack-allocated iterator object similar to GHashTableIter
which allows allocation-free iteration over the members in a JsonObject.
It differs from json_object_foreach_member() in the order in which it
iterates — for JsonObjectIter the order is undefined.
https://bugzilla.gnome.org/show_bug.cgi?id=755509
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Instead of relying on a separate file that requires being update every
time we add a new public function we should use compiler annotations to
let the linker know which symbols are public and exported.
In order to achieve this we have to:
* check for the visibility=hidden attribute
* add -fvisibility=hidden to the linker flags
* add a macro to annotate all public symbols
While we're at it, we should copy the versioned symbols macro layout
already used by GLib, GTK+, and other G* libraries, including the
ability to express the range of allowed versions of JSON-GLib that
third party code can compile against.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
GCC (and other compilers) can optimise multiple inclusion of headers if
they find the:
#ifndef FOO
#define FOO
#endif
pattern as the first thing inside a header. The single-header inclusion
guard was preventing that from happening, so we need to move it inside
the multiple inclusion guard.
|
|
|
|
|
|
|
|
|
|
|
| |
We should simplify the JsonNode API a bit, especially when it comes to
initializing nodes. Instead of a two-step "new(<type>) followed by a
set_<type>(value)" API, we can provide a "init_<type>(value)" API that
can take any existing JsonNode and initialize it to the given type.
This makes the JsonNode creation more concise and reliable; it also
allows to implicitly re-initialize JsonNodes without requiring the user
to de-allocate/re-allocate them first.
|
|
|
|
| |
We have deprecations warnings from the compiler, now.
|
|
|
|
| |
It's the development cycle, we can start using GLib 2.31.
|
|
|
|
|
| |
Instead of using a defined symbol to remove the deprecated functions
from the library, we should use compiler warnings.
|
|
|
|
|
|
|
|
| |
See GLib bug:
https://bugzilla.gnome.org/show_bug.cgi?id=644611
The macro is going to be deprecated soon.
|
|
|
|
| |
JsonNode is fully opaque, so there are no fields to annotate.
|
|
|
|
| |
JsonNode should mimick GValue's API and have macros for easy type checking
|
|
|
|
|
| |
Add the setter for JsonNode:parent, to be used in JsonParser instead
of directly accessing the JsonNode structure.
|
|
|
|
|
|
|
|
|
| |
The correct header file for JSON-GLib is, and has always been,
json-glib.h. Anything else was not supported, as we've been
moving around stuff for a while, now.
This commit enforces the single include file, using the same
policy enacted by other libraries, like: GLib, GTK+ and Clutter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The JSON RFC does not specify the size of the integer type, thus
implicitly falling back to machine-size.
This would all be fine and dandy if some demented Web Developer (and
I use the term "developer" *very much* loosely) did not decide to
use integers to store unique identifiers for objects; obviously, you
can't have more than 2^32-1 status messages in a database with
millions of users who update their status multiple times per day.
Right, Twitter?
Anyway, some languages do a type auto-promotion from Integer to
Long, thus pushing the limit of allowed positive values -- until the
next integer overflow, that is. C, and GLib, do not do that
transparently for us so we need to:
- always use gint64 when parsing a JSON data stream using
JsonScanner
- move all the Node, Object and Array APIs to gint64
- auto-promote G_TYPE_INT to G_TYPE_INT64 when setting
a GValue manually
- auto-promote and auto-demote G_TYPE_INT properties when
(de)serializing GObjects.
The GLib types used internally by JSON-GLib are, thus:
integer -> G_TYPE_INT64
boolean -> G_TYPE_BOOLEAN
float -> G_TYPE_DOUBLE
string -> G_TYPE_STRING
|
|
|
|
|
|
|
|
|
|
| |
The JsonNode structure has always been meant to be completely
opaque; we indirectly exposed the :type member, but only for
access through the JSON_NODE_TYPE() macro.
Since that macro has become a proxy for the json_node_get_node_type()
function we can safely move everything into a private, uninstalled
header file and let JsonNode be completely opaque to the developer.
|
|
|
|
|
|
| |
Similarly to commit 3057a172 for JsonObject, the newly added
json_array_foreach_element() iterates over a JSON array data
type.
|
|
|
|
|
| |
The json_object_foreach_member() function iterates over a JsonObject
data type.
|
|
|
|
|
| |
The json_node_is_null() function is just a quick check for
nodes set to null.
|
|
|
|
|
|
|
|
| |
Second pass at adding type safety to the JsonNode type checks.
The JSON_NODE_TYPE macro now calls the json_node_get_node_type()
function which hides the JsonNode.type structure field and gives
us a little bit more of future compatibility.
|
|
|
|
|
| |
First pass at adding some type safety to the JsonNode type checks,
and at removing every mention of the JsonNode interna fields.
|
|
|
|
|
|
|
|
|
|
| |
Like commit 5bb6ea91 did for JsonObject, we should add typed
convenience accessors to JsonArray in order to cut down the
amount of nodes needed when parsing and generating JSON data
streams.
As for JsonObject, the amount of types is small enough to avoid
the combinatorial API explosion.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The add_member() method of JsonObject has wee bit weird semantics: if
the member to be added already exists it prints a scary warning and
returns - and yet it calls g_hash_table_replace() internally as if it
overwrites the member.
So, instead of changing semantics midway we can:
- add a json_object_set_member() which adds a new member and
overwrites existing members
- deprecate json_object_add_member()
While we're at it, we can add convenience wrappers for set_member()
and get_member() that don't require us toying with nodes; luckily,
since the amount of valid types we can add to a JsonObject is limited,
this does not lead to a combinatorial API explosion.
|
|
|
|
|
|
| |
Getting copies of the nodes might work better for high level languages
binding the JSON-GLib API, because they can manage the lifetime of the
returned values using their own rules.
|
|
|
|
|
|
| |
We need a GType for nodes if we want to add JsonNode properties or signal
marshallers to a GObject class. We could use pointers, but we'd loose type
safety, so it's a no-no.
|
|
|
|
|
|
|
| |
The JsonSerializable interface allows implementations to override the
GObject-to-JSON serialization process, by providing two virtual methods
to control the (de)serialization of GObject properties. This way it's
possible to serialize GObjects with properties holding complex data types.
|
|
|
|
|
| |
To map json_array_get_elements(), a json_object_get_values() method has
been added which returns the list of JsonNodes contained by a JsonObject.
|
|
|
|
|
|
|
| |
Write and document json_object_remove_member() and json_array_remove_element()
which can be used to remove a JsonNode from a JsonObject or a JsonArray
respectively. This way, the JsonObject and JsonArray are API-complete and
the object model can be manipulated in code.
|
|
|
|
|
| |
The newly added json_node_dup_string() is a convenience function for
getting a copy of the string contained inside a JsonNode.
|
|
|
|
|
|
| |
This commit adds some convenience accessors for setting and
getting fundamental types in and from a JsonNode, to avoid
jumping through all the GValue hoops.
|
|
|
|
|
|
|
|
|
|
| |
The type functions for the JsonObject and JsonArray types were declared,
albeit with the wrong return value, but not implemented. This commit
fixed the return value and implements them.
JsonObject and JsonArray are boxed types because we don't need them to
be GObjects (no signals, no inheritance and their implementation must be
completely opaque for the developer).
|
|
|
|
|
| |
Now that we moved the constructors and setters for the JSON data types into
the public symbols we need to document them to get back to 100% doc coverage.
|
|
|
|
|
|
|
| |
Now that we are providing a generator class we need to provide the
constructors and setters for JsonNode, JsonObject and JsonArray. This
also means that the json-private.h header is now useless, so we can
remove it from the build and repository.
|
|
|
|
| |
With this commit, we reach 100% coverage.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This huge commit removes JsonData and adds JsonNode, the generic container
for fundamental and complex data types extracted from a JSON stream. The
contents of a JsonNode can be extracted from it in form of a GValue for
fundamental types (integers, floats, strings, booleans) or in form of
JsonObject and JsonArray objects. JsonObject and JsonArray now accept
JsonNodes instead of GValues.
The JsonParser object builds the data model tree when parsing a JSON stream;
the tree can be recursed by getting the root node and walking it using the
GValue API for the fundamental types and the objects/arrays API for complex
types.
The API has been updated and the tests now recurse through the generated
data model tree.
|
|
|
|
|
|
|
| |
JsonData is like GValue, but it stores JSON data types (objects and
arrays) and allows us to retrieve them safely. This way we can actually
know the type of the objects returned by the parser and by the other
object walking functions.
|
|
JSON-GLib is a JSON parser library written with GLib and GObject.
JSON is the JavaScript Object Notation, and it's used to define objects
and object hierarchies in a human-readable way.
|