» VL: Serialization
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

VL: Serialization

Serialization in VL has drastically been simplified by introducing two new nodes called Serialize and Deserialize in the category System.Serialization.
Let's first have a look at two basic examples:

Serialize takes any value and serializes it into a XElement while Deserialize does the exact opposite, it takes a XElement and turns it into a value of the requested output type.

As you can see from the screenshot the resulting string is very short and contains only the mimimum amount of data. It achieves that tidyness by only serializing user defined properties, skipping properties which have the default value, making use of XML attributes, putting collections of primitive values into comma separated strings and adding type information only when necessary.

When deserializing the system will try to apply the serialized content on the instance to be created. This makes it very resilient to future patch changes as adding or removing properties and to some extend even changing the type of a property will just work.

Serializers are provided for all primtive types (Boolean, Integer32, Float32, etc.), collection types (Array, Spread, Dictionary, etc.), commonly used imported types (Vector2/3/4, Matrix, Color, etc.) and most importantly all patched types. If a serializer should be missing for a certain type either report it to us or keep on reading to the next section where you learn how to patch (or write) your own serializer.

Paired with the new files nodes serialization to disk is straight forward:

That's basically all there is to know from an end-user perspective. You can try these new nodes in the latest alpha versions.

Writing a custom serializer

Even though VL ships with serializers for the most common types the situation could still arise where a custom serializer has to be written - either because it's simply missing for the type in question or one is not satisfied with the output of the already existing serializer.

Creating a custom serializer consists of two steps

  1. Patching (or writing in C#) the serializer by implementing the ISerializer<T> interface using the advanced Serialize and Deserialize nodes working on the SerializationContext
  2. Registering that serializer using the advanced RegisterSerializer node inside the static RegisterServices operation (more on that in an upcoming blog post)

Here are two screenshots of the above from an example implementation which can be found in the VL.CoreLib/help/Serialization.vl file:

We're looking forward to your feedback.

Happy serialization!

Elias, Wednesday, Jul 18th 2018 Digg | Tweet | Delicious 5 comments  
lasal 19/07/2018 - 09:10

yes!

dottore 19/07/2018 - 10:33

super
:)

tobyk 19/07/2018 - 17:34

YES! Badass

velcrome 27/08/2018 - 16:42

just started using it, and found something odd.
it is the fact the Serialize node will omit attributes, if they are zero.

so here I have a Spread of 7 SoftEdges, any of them is defined by its offset, its gamma, and its width.

<Item Gamma="0.64" />
<Item Offset="0.1666667" Scale="0.01" Gamma="0.64" />
<Item Offset="0.3333333" Scale="0.01" Gamma="0.64" />
<Item Offset="0.5" Scale="0.01" Gamma="0.64" />
<Item Offset="0.6666667" Scale="0.01" Gamma="0.64" />
<Item Offset="0.8333333" Scale="0.06" Gamma="0.64" />
<Item Offset="1" Gamma="0.64" />

so after the serialization, there are values missing.
I would rather have this Omission optional, please.

  • using this mechanism to update the data of other (e.g. networked) instances won't ever change them back to the default of a field
  • it makes interop with other (less statically typed) programming dialects just harder on their side
Elias 06/09/2018 - 12:45

@velcrome This option is available on the advanced Serialize (Log Errors) node - name is not perfect and option should probably be available on the simple node also.

  • 1

anonymous user login

Shoutbox

~2d ago

joreg: vvvvTv S0204 is out: Custom Widgets with Dear ImGui: https://youtube.com/live/nrXfpn5V9h0

~2d ago

joreg: New user registration is currently disabled as we're moving to a new login provider: https://visualprogramming.net/blog/2024/reclaiming-vvvv.org/

~9d ago

joreg: vvvvTv S02E03 is out: Logging: https://youtube.com/live/OpUrJjTXBxM

~11d ago

~13d ago

joreg: Follow TobyK on his Advent of Code: https://www.twitch.tv/tobyklight

~17d ago

joreg: vvvvTv S02E02 is out: Saving & Loading UI State: https://www.youtube.com/live/GJQGVxA1pIQ

~17d ago

joreg: We now have a presence on LinkedIn: https://www.linkedin.com/company/vvvv-group

~24d ago

joreg: vvvvTv S02E01 is out: Buttons & Sliders with Dear ImGui: https://www.youtube.com/live/PuuTilbqd9w

~1mth ago

joreg: vvvvTv S02E00 is out: Sensors & Servos with Arduino: https://visualprogramming.net/blog/2024/vvvvtv-is-back-with-season-2/

~1mth ago