Other

The Division of Labor Between XML, JSON and MessagePack

DEV Community: #dotnet Jeff Tsai
Other

A .NET framework keeps persistence on human-readable XML while splitting transport between MessagePack for .NET-to-.NET calls and JSON for JavaScript or third-party clients. The post explains how a per-call format flag, a type allowlist and hand-written MessagePack formatters shape that design.

Key points

  • Persistence goes through XML end to end; transport splits into MessagePack when both ends are .NET and JSON when a JavaScript or third-party caller is involved.
  • PayloadFormat has three values — Plain, Encoded and Encrypted — deciding only what the value slot looks like, not which method runs.
  • Plain values stay a JsonElement and take their type from the method signature, so the type slot is unnecessary; encoded values need a type name on the payload.
  • Serializer is chosen per call, compressor and encryptor per deployment in SystemSettings, and an unknown name throws instead of falling back.
  • Definition-style results such as FormSchema travel as an XML string inside the JSON payload, letting XmlSerializer restore them on every front end.
  • Every MessagePack wire type needs a hand-written formatter and member list, backed by tests that verify registration and detect unreachable entries.
  • Only the encoded route lets the caller pick the target type, so an allowlist filters the full type name before it reaches Type.GetType on the server.

Real-world use

  • An enterprise ERP-style system whose definitions are stored as hand-editable XML files under version control while desktop, browser, iOS and Android clients consume the same API.
  • A pre-login handshake that probes connectivity and fetches shared settings before any transport key exists, so values must travel as readable plain JSON.
  • A multi-client API where a .NET desktop front end wants compact binary payloads while a JavaScript or third-party integration still needs readable JSON.
  • A Native AOT or restricted environment where reflection-based MessagePack resolution is unavailable, so every wire type must be registered explicitly.

This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message