Apart from the registration order, you can define a higher affinity of your writer in order to supersede the standard ones.
Just switch the value returned by the affinity function in the RegisterWriter call from TMARSMessageBodyRegistry.AFFINITY_MEDIUM to TMARSMessageBodyRegistry.AFFINITY_HIGH and your writer will have a priority over the standard record writer.
I would then write the WriteTo implementation like this:
procedure TScimPlusJSONWriter.WriteTo(const AValue: TValue;
const AMediaType: TMediaType; AOutputStream: TStream;
const AActivation: IMARSActivation);
var
LType: TRttiType;
begin
LType := AActivation.MethodReturnType;
if not Assigned(LType) then
Exit; // procedure?
if LType.IsRecord or LType.IsDynamicArrayOfRecord then
TMARSMessageBodyWriter.WriteWith<TRecordWriter>(AValue, AMediaType, AOutputStream, AActivation)
else if LType.IsObjectOfType<TJSONValue> then
TMARSMessageBodyWriter.WriteWith<TJSONValueWriter>(AValue, AMediaType, AOutputStream, AActivation);
AActivation.Response.ContentEncoding := 'UTF-8';
end;
TMARSMessageBodyWriter.WriteWith<> is a new utility function I just introduced in the "develop" branch (MARS.Core.MessageBodyWriter unit, https://github.com/andrea-magni/MARS/commit/e818d7e261e7ef2b9a1c2c714adae459c5585c56#diff-97e07c61cdc46902bf53d808b8117104R157 ). You can simply instantiate the corresponding MessageBodyWriter class as we did before.
Sincerely,