#2381·rapidjson

Recommendation for interfacing rapidjson with polymorphic code?

Author: Brian-at-BaebiesCreated Apr 29, 2026Updated Apr 29, 2026

This is probably a newbish question...but: I have a polymorphic class structure like this:

class Base {
    public:
        virtual void write_json(<Writer-type??>) = 0;
};

class Derived1 : public Base {
    public:
        void write_json(<Writer-type??>) { ... }
};

class Derived2 : public Base {
    public:
        void write_json(<Writer-type??>) { ... } 
};

My classes shouldn't care at all about the specifics of the writer passed in, but since rapidjson heavily depends on CRTP, I either have to declare the function with a fully-specialized Writer object (and lock callers into using only that specialization of Writer) or template the write_json method and lose the polymorphism of my classes.

Is there a recommended approach for gluing CRTP code and dynamic-polymorphic code together?