{%- if json_annotation %}
    static {{ class_name }} from_data(const std::vector<uint8_t>& data, const std::string& content_type) {
        {{ class_name }} result;
        std::string media_type = content_type.substr(0, content_type.find(';'));
        std::vector<uint8_t> decompressed_data = data;
        if (media_type.find("+gzip") != std::string::npos) {
            std::stringstream compressed;
            compressed.write(reinterpret_cast<const char*>(data.data()), data.size());
            std::stringstream decompressed;
            boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
            in.push(boost::iostreams::gzip_decompressor());
            in.push(compressed);
            boost::iostreams::copy(in, decompressed);
            std::string decompressed_str = decompressed.str();
            decompressed_data.assign(decompressed_str.begin(), decompressed_str.end());
            media_type = media_type.substr(0, media_type.find("+gzip"));
        }
        if (media_type == "application/json") {
            std::string json_str(decompressed_data.begin(), decompressed_data.end());
            return nlohmann::json::parse(json_str).get<{{ class_name }}>();
        }
        else {
            throw std::invalid_argument("Unsupported media type: " + media_type);
        }
    }

    std::vector<uint8_t> to_byte_array(const std::string& content_type) const {
        std::vector<uint8_t> result;
        std::string media_type = content_type.substr(0, content_type.find(';'));
        if (media_type == "application/json") {
            std::string json_str = nlohmann::json(*this).dump();
            result.assign(json_str.begin(), json_str.end());
        } 
        if (result.empty()) {
            throw std::invalid_argument("Unsupported media type: " + media_type);
        }
        if (content_type.find("+gzip") != std::string::npos) {
            std::stringstream compressed;
            std::stringstream origin;
            origin.write(reinterpret_cast<const char*>(result.data()), result.size());
            boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
            out.push(boost::iostreams::gzip_compressor());
            out.push(compressed);
            boost::iostreams::copy(origin, out);
            std::string compressed_str = compressed.str();
            result.assign(compressed_str.begin(), compressed_str.end());
        }
        return result;
    }
{%- endif %}
