Skip to content
Download

MACH_DEFINE_JSON

MACH_DEFINE_JSON

Declares JSON serialization support for a type.

Primary header:

#include <mach/Json.hpp>

Convenience header:

#include <mach/mach.hpp>
MACH_DEFINE_JSON(Type, member1, member2, ...)
Parameter Description
Type The type to enable JSON serialization for.
member1, member2, ... The members to serialize and deserialize.
  • 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.
struct LoginRequest {
std::string email;
std::string password;
};
MACH_DEFINE_JSON(LoginRequest, email, password);
Name Description
Results Returns JSON-serializable values from route handlers and controller actions.