vibe.d beta banner
get vibe.d
0.10.0

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.

Example

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;
}

import vibe.data.json;
static assert(is(typeof(serializeToJson(Test()))));
Authors

Sönke Ludwig

Copyright

© 2013-2016 rejectedsoftware e.K.

License

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