Skip to content

Release 0.140.0

Choose a tag to compare

@danielaparker danielaparker released this 28 Nov 07:10
· 7815 commits to master since this release

Changes to the json_type_traits convenience macros:

  • In Issue 190, Twan Springeling
    raised an issue with the macro JSONCONS_GETTER_CTOR_TRAITS_DECL, that it did not come
    with "strict" and "non-strict" versions. In this release we introduce new macros, where
    _N_ is mnemonic for the number of mandatory properties provided (possibly zero), and ALL is
    mnemonic for all properties are mandatory:
JSONCONS_N_GETTER_CTOR_TRAITS_DECL(class_name,num_mandatory_params,
                                   getter_name0,
                                   getter_name1,...) // (11)

JSONCONS_ALL_GETTER_CTOR_TRAITS_DECL(class_name,
                                     getter_name0,getter_name1,...) // (12)

JSONCONS_TPL_N_GETTER_CTOR_TRAITS_DECL(num_template_params,
                                       class_name,num_mandatory_params,
                                       getter_name0,getter_name1,...) // (13)

JSONCONS_TPL_ALL_GETTER_CTOR_TRAITS_DECL(num_template_params,
                                         class_name,
                                         getter_name0,getter_name1,...) // (14)

JSONCONS_N_GETTER_CTOR_NAMED_TRAITS_DECL(class_name,num_mandatory_params,
                                         (getter_name0,"name0"),
                                         (getter_name1,"name1")...) // (15)

JSONCONS_ALL_GETTER_CTOR_NAMED_TRAITS_DECL(class_name,
                                          (getter_name0,"name0"),
                                          (getter_name1,"name1")...) // (16)

JSONCONS_TPL_N_GETTER_CTOR_NAMED_TRAITS_DECL(num_template_params,
                                             class_name,num_mandatory_params,
                                             (getter_name0,"name0"),
                                             (getter_name1,"name1")...) // (17)

JSONCONS_TPL_ALL_GETTER_CTOR_NAMED_TRAITS_DECL(num_template_params,
                                               class_name,
                                               (getter_name0,"name0"),
                                               (getter_name1,"name1")...) // (18)
  • When the traits generated by e.g. JSONCONS_N_GETTER_CTOR_TRAITS_DECL need to pass an argument to a
    constructor that is not present in the JSON, they pass a default constructed parameter value.
    The legacy macros e.g. JSONCONS_GETTER_CTOR_TRAITS_DECL remain, and have the same meaning as before, but are deprecated.

  • With the introduction of the JSONCONS_POLYMORPHIC_TRAITS_DECL macro,
    and the support for polymorhic types, there comes a problem with the "non-strict" macros
    JSONCONS_MEMBER_TRAITS_DECL, JSONCONS_PROPERTY_TRAITS_DECL, JSONCONS_SETTER_GETTER_TRAITS_DECL, etc.,
    when a class has non-mandatory properties. Type selection is based on the presence of properties,
    but the json_type_traits generated by the non-strict macros don't know which properties are mandatory
    and which non-mandatory, hence type selection becomes impossible when members are absent in
    the JSON. For this reason, twelve new _N_ macros have been introduced to allow you to specify which properties
    are mandatory (_N_ is mnemonic for number of mandatory properties):

JSONCONS_N_MEMBER_TRAITS_DECL(class_name,num_mandatory_params,
                              member_name0,member_name1,...)

JSONCONS_TPL_N_MEMBER_TRAITS_DECL(num_template_params,
                                  class_name,num_mandatory_params,
                                  member_name0,member_name1,...)

JSONCONS_N_MEMBER_NAMED_TRAITS_DECL(class_name,num_mandatory_params,
                                    (member_name0,"name0"),
                                    (member_name1,"name1")...)

JSONCONS_TPL_N_MEMBER_NAMED_TRAITS_DECL(num_template_params,
                                        class_name,num_mandatory_params,
                                        (member_name0,"name0"),
                                        (member_name1,"name1")...)

JSONCONS_N_GETTER_CTOR_TRAITS_DECL(class_name,num_mandatory_params,
                                   getter_name0,
                                   getter_name1,...)

JSONCONS_TPL_N_GETTER_CTOR_TRAITS_DECL(num_template_params,
                                       class_name,num_mandatory_params,
                                       getter_name0,getter_name1,...)

JSONCONS_N_GETTER_CTOR_NAMED_TRAITS_DECL(class_name,num_mandatory_params,
                                         (getter_name0,"name0"),
                                         (getter_name1,"name1")...)

JSONCONS_TPL_N_GETTER_CTOR_NAMED_TRAITS_DECL(num_template_params,
                                             class_name,num_mandatory_params,
                                             (getter_name0,"name0"),
                                             (getter_name1,"name1")...)

JSONCONS_N_PROPERTY_TRAITS_DECL(class_name,get_prefix,set_prefix,num_mandatory_params,
                                property_name0,property_name1,...)

JSONCONS_TPL_N_PROPERTY_TRAITS_DECL(num_template_params,
                                    class_name,get_prefix,set_prefix,num_mandatory_params,
                                    property_name0,property_name1,...)

JSONCONS_N_GETTER_SETTER_NAMED_TRAITS_DECL(class_name,num_mandatory_params,
                                          (getter_name0,setter_name0,"name0"),
                                          (getter_name1,setter_name1,"name1")...)

JSONCONS_TPL_N_GETTER_SETTER_NAMED_TRAITS_DECL(num_template_params,
                                               class_name,num_mandatory_params,
                                               (getter_name0,setter_name0,"name0"),
                                               (getter_name1,setter_name1,"name1")...)
  • The legacy non-strict macros remain, and have the same meaning as before, but are deprecated.

  • For consistency with the new naming, and to allow the legacy JSONCONS_GETTER_CTOR_TRAITS_DECL to
    keep the same meaning for backwards compatibility, the _STRICT_ names are deprecated
    and renamed substituting _ALL_ for STRICT.

See json_type_traits
for complete documentation of the convenience macros.