vibe.d beta banner
get vibe.d

Asynchronous I/O that doesn’t get in your way, written in D

Function asArray

Attribute for representing a struct/class as an array instead of an object.

AsArrayAttribute!Policy asArray(alias Policy)() @property;

Usually structs and class objects are serialized as dictionaries mapping from field name to value. Using this attribute, they will be serialized as a flat array instead. Note that changing the layout will make any already serialized data mismatch when this attribute is used.


struct Fields {
	int f1;
	string f2;
	double f3;

struct Test {
	// serialized as name:value pairs ["f1": int, "f2": string, "f3": double]
	Fields object;
	// serialized as a sequential list of values [int, string, double]
	@asArray Fields array;

static assert(is(typeof(serializeToJson(Test()))));

Sönke Ludwig


© 2013-2016 rejectedsoftware e.K.


Subject to the terms of the MIT license, as written in the included LICENSE.txt file.