serialize

Serializes a value with the given serializer.

The serializer must have a value result for the first form to work. Otherwise, use the range based form.

  1. auto serialize(T value, ARGS args)
  2. void serialize(Serializer serializer, T value)
    void
    serialize
    (
    Serializer
    T
    )
    (
    ref Serializer serializer
    ,
    auto ref T value
    )

Examples

Note that there is a convenience function dutils.data.json.serializeToJSON that can be used instead of manually invoking serialize.

import dutils.data.json;

struct Test {
	int value;
	string text;
}

Test test;
test.value = 12;
test.text = "Hello";

JSON serialized = serialize!JSONSerializer(test);
assert(serialized["value"].get!int == 12);
assert(serialized["text"].get!string == "Hello");

See Also

dutils.data.json.JSONSerializer, dutils.data.json.JSONStringSerializer, dutils.data.bson.BsonSerializer

Meta