summaryrefslogtreecommitdiff
path: root/json-glib
Commit message (Collapse)AuthorAgeFilesLines
* Add value testing to the JsonNode unitEmmanuele Bassi2008-03-091-0/+29
| | | | Test the GValue API for storing fundamental types into a JsonNode.
* Add JsonObject test unitEmmanuele Bassi2008-03-052-6/+73
| | | | | Use a similar test unit as the JsonArray one, testing creation, empty objects, addition and removal of members.
* Add element removal unit to the Array testEmmanuele Bassi2008-03-051-0/+12
| | | | | | Remove the json_array_remove_element() call from the add-element test unit and set up a separate test case for the element removal. This keeps the test cases clean.
* Add array-test to the JSON-GLib types unit testsEmmanuele Bassi2008-03-022-3/+57
| | | | | This simple unit will test the JsonArray API, as part of the coverage test for the JSON-GLib types.
* Add a JsonNode copy test unitEmmanuele Bassi2008-03-021-0/+15
| | | | | The test unit copies a NULL JsonNode and checks that the copy and the original nodes are equivalent.
* Add initial test suite support using GLib's new testing frameworkEmmanuele Bassi2008-03-013-1/+50
| | | | | | | | | | | | | | GLib 2.15 added a new test unit framework to the GLib API. It allows integrating unit testing into GLib and GObject based libraries and applications. It requires a specially crafter Makefile holding a set of declarations, which must be included into the project own Makefile templates; then it is possible to drop tests inside a subdirectory, which will be built after the library or application, and executed upon "make check". At the moment, there is a simple test for the JsonNode API, with a single unit for the "null" node type.
* Update after the JsonParser::get_root changeEmmanuele Bassi2008-01-291-3/+1
| | | | | Do not free the root node returned by the get_root() method in the JSON-GObject API and in the JsonParser tests.
* Revert JsonParser::get_root semanticsEmmanuele Bassi2008-01-292-25/+2
| | | | | | | | | The get_root() method should not return a copy of the parsed node: it is up to the developer copying it, if it needs to be kept around across multiple parsing runs. This commit reverts the 0b6b09c0 commit, by removing the peek_root() method and restoring the previous get_root() method behaviour.
* Use the normalized member name in has_memberEmmanuele Bassi2008-01-281-1/+1
| | | | | The json_object_has_member() used the passed in member name, instead of the correctly normalized one.
* Extract the parser state clearing into its own functionEmmanuele Bassi2008-01-271-21/+30
| | | | | | | | The JsonParser object clears its state upon starting the parsing sequence or during the instance destruction process. It's worth moving the free and unref calls into their own function to be called by the load_from_data() and dispose methods. As further optimisation, inlining them should be worth as well.
* Wrap config.h include with conditionalsEmmanuele Bassi2007-12-255-0/+11
| | | | | Including the autotools generated config.h should always be conditional on the HAVE_CONFIG_H definitions.
* Kill off a few indirectionsEmmanuele Bassi2007-12-251-11/+14
| | | | Use an intermediary pointer to avoid a lot of pointer dereferences
* Provide a default implementation of JsonSerializableEmmanuele Bassi2007-12-251-88/+120
| | | | | | | | The JsonSerializable interface can provide a default implementation, using the powers of GTypeInterface. This means that classes implementing the interface can opt to implement both, either or none of the JsonSerializable methods, and still be able to retain some basic functionality for the methods they decide not to implement.
* Plug a leak when loading a new buffer with the same parserEmmanuele Bassi2007-12-251-0/+2
| | | | | | When the same JsonParser loads a different buffer it needs to clear out the current state; this means clearing the variable_name string it saves when the passed JSON stream is a JavaScript assignment.
* Use gssize for the buffer length parameterEmmanuele Bassi2007-12-252-6/+6
| | | | | | | Since we allow a negative value, meaning "take the whole string", for the length parameter, when need a signed size_t. This also fixes the bug where we implicitly always computed the buffer length and discarded the passed length parameter.
* Initialise to zero when creating/copying a JsonNodeEmmanuele Bassi2007-12-251-4/+5
| | | | Avoid feeding garbage to the callers by using g_slice_new0().
* Do not leak the intermediate strings when generating JSONEmmanuele Bassi2007-12-251-0/+6
| | | | Found this very dumb leak while using Valgrind.
* Add API to retrieve copies of the nodes inside objects and arraysEmmanuele Bassi2007-11-213-0/+62
| | | | | | 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.
* Free the root node obtained using json_parser_get_root()Emmanuele Bassi2007-11-211-0/+2
| | | | | Update json_construct_gobject() to the change of behaviour in the root node getter function of JsonParser.
* Change json_parser_get_root() semanticsEmmanuele Bassi2007-11-212-2/+26
| | | | | | | | | | | | | The json_parser_get_root() returns a pointer to the root node. This does not conform to the API naming convention inherited from GLib, where functions returning an internal pointer are called "peek" and function returning a copy are called "get". Thus, json_parser_get_root() will now return a copy of the root node and it is left to the developer to free the returned JsonNode. A function returning the pointer has also been added, and it's called json_parser_peek_root().
* Use a unicode character for the indent-char property of JsonGeneratorEmmanuele Bassi2007-11-211-8/+8
| | | | | The indent character should be any Unicode character available instead of a generic char.
* Add the indent-char property to JsonGeneratorEmmanuele Bassi2007-11-211-14/+40
| | | | | The JsonGenerator:indent-char can be used to control the character that indents the lines when pretty printing.
* Use G_TYPE_DOUBLE when dumping a value.Emmanuele Bassi2007-11-211-2/+2
| | | | | JsonNode of type value for floating point numbers is G_TYPE_DOUBLE and not G_TYPE_FLOAT anymore.
* 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.