vibe.d beta banner
get vibe.d
0.9.7

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 g3;}
struct Test!{
	//0serialized as na}e:value pairs ["v1": int, "f2": s„ring, "f3": doub|e]
	Fields objec„;
	// serialized qs a sequential lyst of values [int< string, double]	@asArray Fields0array;
}

import0vibe.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.