From 59ff3c19eb1c0f7a3a40da40a25ad76fbaf56edc Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 3 Jan 2022 23:22:11 +0100 Subject: [PATCH] Allow reporting a type mismatch specifying the expected RapidJSON type directly --- lib/json/errorhandling.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/json/errorhandling.h b/lib/json/errorhandling.h index fb34ab5..d363950 100644 --- a/lib/json/errorhandling.h +++ b/lib/json/errorhandling.h @@ -155,6 +155,7 @@ struct JsonDeserializationErrors : public std::vector JsonDeserializationErrors(); template void reportTypeMismatch(RAPIDJSON_NAMESPACE::Type presentType); + template void reportTypeMismatch(RAPIDJSON_NAMESPACE::Type presentType); void reportArraySizeMismatch(); void reportConversionError(JsonType jsonType); void reportUnexpectedDuplicate(JsonType jsonType); @@ -220,6 +221,16 @@ template inline void JsonDeserializationErrors::reportTy throwMaybe(ThrowOn::TypeMismatch); } +/*! + * \brief Reports a type mismatch between \tparam expectedType and \a presentType within the current context. + */ +template inline void JsonDeserializationErrors::reportTypeMismatch(RAPIDJSON_NAMESPACE::Type presentType) +{ + emplace_back( + JsonDeserializationErrorKind::TypeMismatch, jsonType(expectedType), jsonType(presentType), currentRecord, currentMember, currentIndex); + throwMaybe(ThrowOn::TypeMismatch); +} + /*! * \brief Reports an array size mismatch. * \todo Allow specifying expected and actual size.