module ViewModel::Controller

def prerender_viewmodel(viewmodel, status: nil, serialize_context: viewmodel.class.try(:new_serialize_context))

Render viewmodel(s) to a JSON API response as a String
def prerender_viewmodel(viewmodel, status: nil, serialize_context: viewmodel.class.try(:new_serialize_context))
  encode_jbuilder do |json|
    json.data do
      ViewModel.serialize(viewmodel, json, serialize_context: serialize_context)
    end
    if serialize_context && serialize_context.has_references?
      json.references do
        serialize_context.serialize_references(json)
      end
    end
    yield(json) if block_given?
  end
end