-
Pl
chevron_right
Alley Chaggar: Final Report
news.movim.eu / PlanetGnome • 3 days ago - 00:00 • 3 minutes
Intro:
Hi everyone, it’s the end of GSoc! I had a great experience throughout this whole process. I’ve learned so much. This is essentially the ‘final report’ for GSoC, but not my final report for this project in general by a long shot. I still have so much more I want to do, but here is what I’ve done so far.
Project:
JSON, YAML, and/or XML emitting and parsing integration into Vala’s compiler.
Mentor:
I would like to thank Lorenz Wildberg for being my mentor for this project, as well as the Vala community .
Description:
The main objective of this project is to integrate direct syntax support for parsing and emitting JSON, XML, and/or YAML formats in Vala. This will cut back the boilerplate code, making it more user-friendly and efficient for developers working with these formatting languages.
What I’ve done:
Research
- I’ve done significant research in both JSON and YAML parsing and emitting in various languages like C#, Java, Rust and Python.
- Looked into how Vala currently handles JSON using JSON GLib classes, and I then modelled the C code after the examples I collected.
- Modelled the JSON module after other modules in the codegen, specifically, mainly after Dbus, Gvariant, GObject, and GTK.
Custom JSON Overrides and Attribute
- Created Vala syntax sugar specifically making a [JSON] attribute to do serialization.
- Built support for custom overrides as in mapping JSON keys to differently named fields/properties.
- Reduced boilerplate by generating C code behind the scenes.
Structs
- I’ve created both Vala functions to deserialize and serialize structs using JSON boxed functions.
-
I created a Vala
generate_struct_serialize_func
function to create a C code function called_ % s_serialize_func
to serialize fields. -
I then created a Vala function
generate_struct_to_json
to create a C code function called_json_ % s_serialize_mystruct
to fully serialize the struct by using boxed serialize functions.
-
I created a Vala
generate_struct_deserialize_func
function to create a C code function called_ % s_deserialize_func
to deserialize fields. -
I then created a Vala function
generate_struct_to_json
to create a C code function called_json_ % s_deserialize_mystruct
to fully deserialize the struct by using boxed deserialized functions.
GObjects
- I’ve created both Vala functions to deserialize and serialize GObjects using json_gobject_serialize and JSON generator.
-
I then created a Vala function
generate_gclass_to_json
to create a C code function called_json_ % s_serialize_gobject_myclass
to fully serialize GObjects.
-
I created a Vala
generate_gclass_from_json
function to create a C code function called_json_ % s_deserialize_class
to deserialize fields.
Non-GObjects
- I’ve done serializing of non-GObjects using JSON GLib’s builder functions.
-
I then created a Vala function
generate_class_to_json
to create a C code function called_json_ % s_serialize_myclass
to fully serialize non-objects that aren’t inheriting from Object or Json.Serializable.
Future Work:
Research
- Research still needs to be put into integrating XML and determining which library to use.
- The integration of YAML and other formatting languages not only JSON, YAML, or XML.
Custom Overrides and Attributes
- I want to create more specialized attributes for JSON that only do serialization or deserialization. Such as [JsonDeserialize] and [JsonSerialize] or something similar.
- [JSON] attribute needs to do both deserializing and serializing, and at the moment, the deserializing code has problems.
-
XML, YAML, and other formating languages will follow very similar attribute patterns:
[Yaml] , [ Xml ], [ Json ]
.
Bugs
- unref c code functions are calling nulls, which shouldn’t be the cause. They need proper types going through.
- Deserializing prompts a redefinition that needs to be corrected.
- Overridden GObject properties need to have setters made to be able to get the values.
Links
- Here is the JSON module that has majority of the code.
- Here is the merge request .