--- src/common/json.hpp.orig 2019-04-08 14:37:06 UTC +++ src/common/json.hpp @@ -878,6 +878,16 @@ struct is_compatible_object_type_impl::value; }; +template +struct is_compatible_string_type_impl : std::false_type {}; + +template +struct is_compatible_string_type_impl +{ + static constexpr auto value = + std::is_same::value; +}; + template struct is_compatible_object_type { static auto constexpr value = is_compatible_object_type_impl< @@ -886,6 +896,15 @@ template ::value; }; +template +struct is_compatible_string_type +{ + static auto constexpr value = is_compatible_string_type_impl < + conjunction>, + has_value_type>::value, + typename BasicJsonType::string_t, CompatibleStringType >::value; +}; + template struct is_basic_json_nested_type { static auto constexpr value = std::is_same::value @@ -1137,6 +1156,25 @@ template void from_json(const { JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); } + s = *j.template get_ptr(); +} + +template < + typename BasicJsonType, typename CompatibleStringType, + enable_if_t < + is_compatible_string_type::value and + not std::is_same::value and + std::is_constructible < + BasicJsonType, typename CompatibleStringType::value_type >::value, + int > = 0 > +void from_json(const BasicJsonType& j, CompatibleStringType& s) +{ + if (JSON_UNLIKELY(not j.is_string())) + { + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); + } + s = *j.template get_ptr(); }