FAQ: Formatters¶
Which Formatter Should I Use?¶
For most new .NET applications:
MsJsonDataFormatter
is the recommended starting point.
It integrates naturally with System.Text.Json and modern ASP.NET Core applications.
When Should I Use Newtonsoft.Json?¶
Use Newtonsoft.Json when:
- existing applications already depend on it;
- custom converters are required;
- advanced serializer behavior is needed;
- compatibility is important.
What Is The Difference Between JsonDataFormatter And RwJsonDataFormatter?¶
JsonDataFormatter uses:
JsonConvert
and a straightforward serialization pipeline.
RwJsonDataFormatter uses:
StringReader
StringWriter
JsonTextReader
JsonTextWriter
JsonSerializer
and was introduced to reduce memory allocations and GC pressure.
Is RwJsonDataFormatter Faster?¶
Not necessarily in every scenario.
Its primary goal is reducing allocation pressure rather than guaranteeing lower execution time.
Actual performance depends on:
- payload size;
- message volume;
- runtime environment;
- serializer configuration.
Do Formatters Work With JSON Strings?¶
Not directly.
IDataFormatter produces and consumes:
byte[]
payloads.
Internally, some formatter implementations may use JSON strings.
What Is IJsonSerializer?¶
IJsonSerializer is a lower-level abstraction that works with JSON strings.
It is distinct from:
IDataFormatter
which works with broker payloads.
Can I Create A Custom Formatter?¶
Yes.
Applications can implement:
IDataFormatter
to support custom payload formats.
Examples:
- binary serialization;
- encrypted payloads;
- compressed payloads;
- proprietary protocols.
Must Publisher And Subscriber Use The Same Formatter?¶
They must use compatible payload formats.
Using the same formatter implementation on both sides is generally the safest approach.
Can I Customize Serializer Settings?¶
Yes.
Both formatter families support serializer configuration through their underlying serializer components.
Examples:
JsonSerializerOptions
JsonSerializerSettings
depending on the selected implementation.