Hi,
I'm trying out Vibe.D and really liking it so far. Thanks Sönke for the amazing work you have put into this.
I had one question for which I am unable to solve. I often use Typedef to make my code more typesafe. How can I use Typedef with Vibe.D's serialization framework?
For example, say I have:
alias QuestionId = Typedef!(int, -1, "QuestionId");
alias StudentId = Typedef!(int, -1, "StudentId");
enum Actions : int { skip, correct, incorrect }
struct QuestionAttempts
{
StudentId studentId;
QuestionId questionId;
@byName Actions action;
}
Here, QuestionId and StudentId are wrappers on integers such that I don't allow them to mix. I do conversions to and from ints at the boundary (where I interact with the outside world via APIs, etc). That way I reduce the possibility of errors in my D code while communicating in the same manner with the outside world as if they were ints.
unittest
{
auto str1 = "{\"studentId\":3,\"questionId\":42,\"action\":\"skip\"";
auto qa1 = deserializeJson!QuestionAttempts(str1);
}
How can I get the above code to work? Any pointers would be greatly appreciated.
Thanks,
Saurabh