Ahh, I got it - this is how you got the JSON serializer working properly.  You might want to look at what jsonapi does and see if the other json libraries have a way of doing this as well.  The different json libs have very different performance profiles, so this can be important in a performance critical application.