| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
| |
To avoid reimplementing the same code all over again, if the implementation
of the serialize_property virtual function of JsonSerializable returns NULL
we will fall back to the simple value-to-node generator we provide for
non-serializable classes.
|
|
|
|
|
|
| |
We need to skip if the CONSTRUCT_ONLY flag is set, not unset. We also need
to copy the value from the JSON node into the target GValue, not the other
way around.
|
|
|
|
|
|
|
|
|
| |
The fallback parser for json_construct_gobject() is invoked if the GType
does not implement the JsonSerializable interface, or if the interface
was not handling the property.
It will natively convert integers, booleans, strings and double precision
floating point values; it also handles string vectors in form of arrays.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
JsonGenerator now has a :root property, so it can be constructed using
just g_object_new():
generator = g_object_new (JSON_TYPE_GENERATOR,
"pretty", TRUE,
"indent", 4,
"root", node,
NULL);
This means that the root node is copied inside the generator, instead of
just taking ownership (it was quite confusing). The documentation now
clearly states what happens, and that you can safely free the node after
feeding it to the JsonGenerator.
|
|
|
|
| |
JsonNode payload is inside a union.
|
|
|
|
|
|
| |
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 json_construct_gobject() function takes a GType and a JSON data stream
and constructs a new instance for the given type. If the type is a
JsonSerializable, it will use the JsonSerializable interface for parsing
the JsonNodes of each object member.
This is the initial implementation of the function: the JsonNode-to-GValue
fallback parser is just a stub.
|
|
|
|
| |
Add a check for commas after complex data types inside object members.
|
|
|
|
| |
Catch missing commas after an array element or an object member.
|
|
|
|
|
|
|
|
|
|
| |
The copy of JSON-GLib in Clutter trunk has two fixes for the JsonParser
object:
* support for negative numbers (ints and floats);
* correct parse error propagation
which should make the JsonParser hopefully complete.
|
|
|
|
|
| |
Before calling json_object_unref() or json_array_unref() in json_node_free()
we need to check if the payload of JsonNode is set to avoid a critical.
|
|
|
|
| |
A placeholder, while syntactically correct, won't do.
|
|
|
|
|
| |
This is what happens when you fix a compiler warning about a shadowing
variable and you don't run the test suite to check the results.
|
| |
|
| |
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
| |
Every member name is stored inside the internal hash table of JsonObject
using a normalized string: every delimiter found matching G_STR_DELIMITERS
is automatically transformed in an underscore ('_').
This means that "member-name" and "member_name" are completely equivalent
for a JsonObject.
|
|
|
|
|
|
|
| |
Even though GLib 2.14 is now available, many systems still come out with
GLib 2.12. Since we are using just a single 2.14 function for retrieving
the members from a JsonObject, we can provide an internal version of that
function and hideit behind a pre-processor macro.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
If the root node contains just a bare value (true, false, null, fundamental
type) then it's still valid JSON.
Also, use the commodity JsonNode API to avoid using values in the parser
code.
|
|
|
|
|
| |
The newly added json_node_dup_string() is a convenience function for
getting a copy of the string contained inside a JsonNode.
|
|
|
|
|
| |
When adding a JsonNode to a JsonObject or a JsonArray, the containers
take ownership of the node.
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
GScanner advertise the floating point values as floats, but it really
uses doubles. Hence, we need to use G_TYPE_DOUBLE when saving the
parsed constants into a GValue.
|
|
|
|
|
|
| |
Add two methods to JsonParser to retrieve the currently parsed line
and position within that line. These methods works only while parsing,
so within the signal handlers and inside subclasses.
|
| |
|
|
|
|
|
|
|
| |
JsonParser should emit signals in critical places, like: start/end of
the parsing process; start and end of a JsonObject and a JsonArray;
completion of every member and element of a JsonObject and a JsonArray.
These signals require the addition of some custom marshaller.
|
|
|
|
|
|
|
|
|
|
| |
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).
|
|
|
|
|
| |
This commit adds json-gobject.h and json_serialize_gobject() to
JSON-GLib, to serialize a GObject instance into a JSON data stream.
|
|
|
|
|
| |
JsonGenerator can now create objects and array-nested objects, with and without
pretty printing. The test suite has been updated accordingly.
|
|
|
|
|
| |
JsonGenerator now supports nested arrays, both with and without pretty
printing. The tests suite has been updated accordingly.
|
|
|
|
|
|
|
| |
JsonGenerator now can create simple arrays, with "pretty" enabled and disabled.
Simple arrays are just one-level, value-only arrays.
The test unit has been updated to exercise this new feature.
|
| |
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
JsonGenerator is an object that creates JSON data streams from a data
model tree. This commit adds the JsonGenerator class to the build and
API reference.
|
|
|
|
| |
With this commit, we reach 100% coverage.
|
|
|
|
|
| |
It seems that the parent accessor fell through. This commit implements
the declared json_node_get_parent() function.
|
| |
|
|
|
|
|
| |
Use gtk-doc to build the various bits and pieces of the API reference
for JSON-GLib.
|
|
|
|
|
| |
The comma is used as a member and element separator, so it should be
swallowed by the parser as soon as possible.
|
|
|
|
|
|
| |
This commit completes the JsonParser class by adding the ability to
parse JSON objects, either alone or inside arrays. JsonParser is now
a JSON parser.
|
|
|
|
|
|
|
| |
JsonParser uses the take variant of JsonNode setters for objects and arrays
since it's the one creating the objects. This way, we avoid leaks and the
extra complexity of unreffing the newly created complex containers after
setting them into the JsonNodes.
|
|
|
|
|
| |
When parsing a JSON node we need to correctly set up the parent node
of the newly created ones.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
Since there cannot be any other token except for the comma, which we
eat anyway, there's no point in going through the switch() check
after we have finished parsing a nested array.
|
|
|
|
|
|
|
| |
Add the array parsing code. The parser identifies and builds nested
levels of arrays, but the storage is not quite right. That is a problem
of the parser object, though, so this can be considered a first raw
pass at the problem.
|