MACH_DEFINE_JSON
MACH_DEFINE_JSON
Description
Section titled “Description”Declares JSON serialization support for a type.
Headers
Section titled “Headers”Primary header:
#include <mach/Json.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”MACH_DEFINE_JSON(Type, member1, member2, ...)Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
Type |
The type to enable JSON serialization for. |
member1, member2, ... |
The members to serialize and deserialize. |
Remarks
Section titled “Remarks”- The macro must be placed in the same namespace as the type.
- Only the listed members participate in serialization and deserialization.
- When the type is used as a request body, Mach automatically deserializes the incoming JSON before invoking the endpoint.
- If deserialization fails, Mach rejects the request with an appropriate 400 Bad Request response.
- Unknown JSON properties are ignored during deserialization.
- Missing required properties result in a 400 Bad Request response.
- Default member initializers are not applied when a JSON property is missing.
Example
Section titled “Example”struct LoginRequest { std::string email; std::string password;};
MACH_DEFINE_JSON(LoginRequest, email, password);See Also
Section titled “See Also”| Name | Description |
|---|---|
Results |
Returns JSON-serializable values from route handlers and controller actions. |