summaryrefslogtreecommitdiff
path: root/json-glib
Commit message (Collapse)AuthorAgeFilesLines
* Allow deserialization of strings into enums/flagsEmmanuele Bassi2007-11-201-0/+170
| | | | | | | | If the target value is a G_TYPE_ENUM or a G_TYPE_FLAGS we can effectively deserialize a string into the corresponding value (or bit mask) using the introspection API for the GEnum and GFlags types. This code is taken from ClutterScript and it was adapted from GtkBuilder.
* Fix variable shadowing for distcheckEmmanuele Bassi2007-11-131-2/+2
|
* Change "responsible" to "asked" in the (de)serialization functions docsEmmanuele Bassi2007-11-131-7/+8
| | | | | We provide fallbacks in case a JsonSerializable object does not translate a property into a JSON object member and vice versa.
* Merge branch 'gobject-deserialize' into workEmmanuele Bassi2007-11-135-27/+350
|\
| * Use the fallback value-to-node generator even for serializablesgobject-deserializeEmmanuele Bassi2007-11-131-6/+11
| | | | | | | | | | | | | | 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.
| * Fix a couple of dumb typos in the GObject deserialization codeEmmanuele Bassi2007-11-131-2/+4
| | | | | | | | | | | | 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.
| * Add node-to-property simple fallback parser for deserializationEmmanuele Bassi2007-11-131-9/+85
| | | | | | | | | | | | | | | | | | 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.
| * Add the JsonGenerator:root propertyEmmanuele Bassi2007-11-131-2/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Fix member name in json_node_get_value_type()Emmanuele Bassi2007-11-131-1/+1
| | | | | | | | JsonNode payload is inside a union.
| * Add a GType for JsonNodeEmmanuele Bassi2007-11-132-2/+54
| | | | | | | | | | | | 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.
| * Initial implementation of GObject deserialization functionEmmanuele Bassi2007-11-102-14/+176
| | | | | | | | | | | | | | | | | | | | 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.
* | When parsing a full assignment, also swallow any trailing semi-colonEmmanuele Bassi2007-11-101-1/+11
| | | | | | | | | | | | There's no end to web developers insanity when they can twist and turn a perfectly simple and elegant notation into something that allows lazyness and breakage.
* | Add support for parsing assignmentsEmmanuele Bassi2007-11-102-2/+83
|/ | | | | | | | | | | | | | | | | Some JSON web APIs return a full JavaScript assignment instead of just the data structure (and I'm looking at you, Tumblr). This is done in clear violation of the grammar published in the RFC 4627, and it's evidently done because most web developers are too lazy for doing a var foo = eval('(' + text ')'); and want everything defined for them. JsonParser will blissfully ignore the left-hand part of the assignment but, in the interest of the developer who cares, will record: 1. that the parsed statement was in fact an assignment and 2. the name of the variable used. The function json_parser_has_assignment() can be used to query both the presence of an assignment and the variable name at the same time.
* More sanity checks for objectsEmmanuele Bassi2007-10-291-1/+7
| | | | Add a check for commas after complex data types inside object members.
* Add more sanity checks to the parserEmmanuele Bassi2007-10-291-0/+10
| | | | Catch missing commas after an array element or an object member.
* Backport fixes from Clutter trunkEmmanuele Bassi2007-10-291-20/+103
| | | | | | | | | | 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.
* Check if the payload is set in json_node_free()Emmanuele Bassi2007-10-291-2/+4
| | | | | 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.
* We need the actual implementation of the JsonSerializable GType functionEmmanuele Bassi2007-10-161-0/+6
| | | | A placeholder, while syntactically correct, won't do.
* Fix the compiler fixesEmmanuele Bassi2007-10-161-4/+6
| | | | | 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.
* Fix compilation errors with extra maintainer CFLAGSEmmanuele Bassi2007-10-163-11/+11
|
* Fix EXTRA_DIST files for distcheckEmmanuele Bassi2007-10-161-7/+9
|
* Add the JsonSerializable interfaceEmmanuele Bassi2007-10-163-31/+209
| | | | | | | 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.
* Add a method for getting all the nodes from a JsonObjectEmmanuele Bassi2007-10-162-0/+42
| | | | | 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.
* Add a note in the JsonObject documentation for the member name normalizationEmmanuele Bassi2007-10-161-1/+5
|
* Normalize every member name before using itEmmanuele Bassi2007-10-161-5/+26
| | | | | | | | | 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.
* Provide an internal g_hash_table_get_keys() and bump down GLib dependencyEmmanuele Bassi2007-10-151-0/+25
| | | | | | | 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.
* Add API for removing nodes from arrays and objectsEmmanuele Bassi2007-10-153-61/+100
| | | | | | | 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.
* Parse bare root valuesEmmanuele Bassi2007-10-101-50/+29
| | | | | | | | 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.
* Add json_node_dup_string()Emmanuele Bassi2007-10-082-0/+21
| | | | | The newly added json_node_dup_string() is a convenience function for getting a copy of the string contained inside a JsonNode.
* Fix documentation about the ownership of the nodesEmmanuele Bassi2007-10-072-7/+13
| | | | | When adding a JsonNode to a JsonObject or a JsonArray, the containers take ownership of the node.
* Add convenience accessors for fundamental types in JsonNodeEmmanuele Bassi2007-10-052-0/+213
| | | | | | 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.
* Use doubles when parsing, not floatsEmmanuele Bassi2007-10-051-4/+4
| | | | | | 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 line/position getters to JsonParserEmmanuele Bassi2007-10-052-12/+55
| | | | | | 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.
* Document the newly added signalsEmmanuele Bassi2007-10-052-1/+73
|
* Add more signals to the JsonParser classEmmanuele Bassi2007-10-053-6/+141
| | | | | | | 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.
* Implement the GType functions for JsonObject and JsonArrayEmmanuele Bassi2007-10-053-2/+28
| | | | | | | | | | 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).
* Add GObject serialization support for JSON-GLibEmmanuele Bassi2007-10-023-0/+204
| | | | | This commit adds json-gobject.h and json_serialize_gobject() to JSON-GLib, to serialize a GObject instance into a JSON data stream.
* Add objects supportEmmanuele Bassi2007-10-021-3/+122
| | | | | JsonGenerator can now create objects and array-nested objects, with and without pretty printing. The test suite has been updated accordingly.
* Add nested arrays supportEmmanuele Bassi2007-10-011-0/+10
| | | | | JsonGenerator now supports nested arrays, both with and without pretty printing. The tests suite has been updated accordingly.
* Simple arrays generationEmmanuele Bassi2007-10-011-5/+155
| | | | | | | 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.
* Add missing json-generator.h headerEmmanuele Bassi2007-10-011-0/+1
|
* Document the new public functionsEmmanuele Bassi2007-10-014-0/+117
| | | | | 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.
* Move data types ctors and setters into the public headersEmmanuele Bassi2007-10-018-48/+32
| | | | | | | 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.
* Add stub class for JsonGeneratorEmmanuele Bassi2007-10-013-0/+339
| | | | | | 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.
* Complete API reference of JSON-GLibEmmanuele Bassi2007-10-012-0/+39
| | | | With this commit, we reach 100% coverage.
* Implement json_node_get_parent()Emmanuele Bassi2007-10-011-0/+16
| | | | | It seems that the parent accessor fell through. This commit implements the declared json_node_get_parent() function.
* Add licensing informations to the source codeEmmanuele Bassi2007-10-017-14/+202
|
* Add API reference for JSON-GLibEmmanuele Bassi2007-10-012-1/+9
| | | | | Use gtk-doc to build the various bits and pieces of the API reference for JSON-GLib.
* Swallow the comma earlier in the parserEmmanuele Bassi2007-10-011-9/+16
| | | | | The comma is used as a member and element separator, so it should be swallowed by the parser as soon as possible.
* Add JSON object parsingEmmanuele Bassi2007-10-011-15/+220
| | | | | | 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.