On Fri, 09 Oct 2015 19:36:46 GMT, Sönke Ludwig wrote:
Two possibilities, either use a wrapper struct:
struct UUIDWrapper { UUID value; alias value this; string toString() const { return value.toString(); } static UUID fromString(string str) { return UUID(str); } } assert(uuid.serializeToJson() == Json(uuid.toString()));
or use the serialization policy feature:
template Policy(T) if (is(T == UUID)) { static string toRepresentation(UUID value) { return value.toString(); } static UUID fromRepresentation(string str) { return UUID(str); } } assert(uuid.serializeWithPolicy!(JsonSerializer, Policy) == Json(uuid.toString());
Hi,
the wrapper seems a bit clunky for my case, but I like the serialization policy. However, I am not sure, how to use the policy with the Rest interface generator.
Suppose I have this code:
struct SomeIDs
{
UUID id1,
UUID id2
}
interface API
{
@property someIDs getIDs();
}
class RestServer : API
{
private URLRouter _router;
public:
this() {
_router = new URLRouter();
_router.registerRestInterface(this, MethodStyle.camelCase);
}
...
}
Where do I apply the policy?
Thanks,
Martin