Reflection for RapidJSON
0.0.17
Reflection for serializing/deserializing with RapidJSON
Toggle main menu visibility
Loading...
Searching...
No Matches
json
errorformatting.h
Go to the documentation of this file.
1
#ifndef REFLECTIVE_RAPIDJSON_JSON_ERROR_FORMATTING_H
2
#define REFLECTIVE_RAPIDJSON_JSON_ERROR_FORMATTING_H
3
8
9
#include "
./errorhandling.h
"
10
11
#include <c++utilities/conversion/stringbuilder.h>
12
13
#include <string_view>
14
15
namespace
ReflectiveRapidJSON
{
16
17
inline
std::string_view
jsonTypeToString
(
JsonType
jsonType
)
18
{
19
switch
(
jsonType
) {
20
case
ReflectiveRapidJSON::JsonType::Null
:
21
return
"null"
;
22
case
ReflectiveRapidJSON::JsonType::Number
:
23
return
"number"
;
24
case
ReflectiveRapidJSON::JsonType::Bool
:
25
return
"bool"
;
26
case
ReflectiveRapidJSON::JsonType::String
:
27
return
"string"
;
28
case
ReflectiveRapidJSON::JsonType::Array
:
29
return
"array"
;
30
case
ReflectiveRapidJSON::JsonType::Object
:
31
return
"object"
;
32
default
:
33
return
"?"
;
34
}
35
}
36
37
inline
std::string
formatJsonDeserializationError
(
const
JsonDeserializationError
&error)
38
{
39
using namespace
CppUtilities;
40
std::string_view errorKind;
41
std::string additionalInfo;
42
switch
(error.
kind
) {
43
case
JsonDeserializationErrorKind::TypeMismatch
:
44
errorKind =
"type mismatch"
;
45
additionalInfo =
": expected \""
%
jsonTypeToString
(error.
expectedType
) %
"\", got \""
%
jsonTypeToString
(error.
actualType
) +
'\"'
;
46
break
;
47
case
JsonDeserializationErrorKind::ArraySizeMismatch
:
48
errorKind =
"array size mismatch"
;
49
break
;
50
case
JsonDeserializationErrorKind::ConversionError
:
51
errorKind =
"conversion error"
;
52
break
;
53
case
JsonDeserializationErrorKind::UnexpectedDuplicate
:
54
errorKind =
"unexpected duplicate"
;
55
break
;
56
case
JsonDeserializationErrorKind::InvalidVariantObject
:
57
errorKind =
"invalid variant object"
;
58
break
;
59
case
JsonDeserializationErrorKind::InvalidVariantIndex
:
60
errorKind =
"invalid variant index"
;
61
break
;
62
default
:
63
errorKind =
"semantic error"
;
64
}
65
if
(error.
record
&& error.
member
) {
66
return
errorKind %
" within record \""
% error.
record
%
"\" and member \""
% error.
member
%
'\"'
+ additionalInfo;
67
}
else
if
(error.
record
&& error.
index
!=
JsonDeserializationError::noIndex
) {
68
return
errorKind %
" within record \""
% error.
record
%
"\" and index \""
% error.
index
%
'\"'
+ additionalInfo;
69
}
else
if
(error.
record
) {
70
return
errorKind %
" within record \""
% error.
record
%
'\"'
+ additionalInfo;
71
}
else
{
72
return
errorKind %
" in document"
+ additionalInfo;
73
}
74
}
75
76
}
// namespace ReflectiveRapidJSON
77
78
#endif
// REFLECTIVE_RAPIDJSON_JSON_ERROR_FORMATTING_H
errorhandling.h
Contains helper for error handling when deserializing JSON files.
ReflectiveRapidJSON
Definition
traits.h:13
ReflectiveRapidJSON::formatJsonDeserializationError
std::string formatJsonDeserializationError(const JsonDeserializationError &error)
Definition
errorformatting.h:37
ReflectiveRapidJSON::jsonTypeToString
std::string_view jsonTypeToString(JsonType jsonType)
Definition
errorformatting.h:17
ReflectiveRapidJSON::JsonDeserializationErrorKind::TypeMismatch
@ TypeMismatch
Definition
errorhandling.h:25
ReflectiveRapidJSON::JsonDeserializationErrorKind::InvalidVariantObject
@ InvalidVariantObject
Definition
errorhandling.h:29
ReflectiveRapidJSON::JsonDeserializationErrorKind::ConversionError
@ ConversionError
Definition
errorhandling.h:27
ReflectiveRapidJSON::JsonDeserializationErrorKind::ArraySizeMismatch
@ ArraySizeMismatch
Definition
errorhandling.h:26
ReflectiveRapidJSON::JsonDeserializationErrorKind::InvalidVariantIndex
@ InvalidVariantIndex
Definition
errorhandling.h:30
ReflectiveRapidJSON::JsonDeserializationErrorKind::UnexpectedDuplicate
@ UnexpectedDuplicate
Definition
errorhandling.h:28
ReflectiveRapidJSON::JsonType
JsonType
The JsonType enum specifies the JSON data type.
Definition
errorhandling.h:37
ReflectiveRapidJSON::JsonType::String
@ String
Definition
errorhandling.h:41
ReflectiveRapidJSON::JsonType::Array
@ Array
Definition
errorhandling.h:42
ReflectiveRapidJSON::JsonType::Object
@ Object
Definition
errorhandling.h:43
ReflectiveRapidJSON::JsonType::Number
@ Number
Definition
errorhandling.h:39
ReflectiveRapidJSON::JsonType::Null
@ Null
Definition
errorhandling.h:38
ReflectiveRapidJSON::JsonType::Bool
@ Bool
Definition
errorhandling.h:40
ReflectiveRapidJSON::jsonType
constexpr JsonType jsonType()
Definition
errorhandling.h:50
ReflectiveRapidJSON::JsonDeserializationError
The JsonDeserializationError struct describes any errors of fromJson() except such caused by invalid ...
Definition
errorhandling.h:109
ReflectiveRapidJSON::JsonDeserializationError::expectedType
JsonType expectedType
The expected type (might not be relevant for all error kinds).
Definition
errorhandling.h:116
ReflectiveRapidJSON::JsonDeserializationError::index
std::size_t index
The index in the array which was being processed when the error was ascertained.
Definition
errorhandling.h:124
ReflectiveRapidJSON::JsonDeserializationError::actualType
JsonType actualType
The actual type (might not be relevant for all error kinds).
Definition
errorhandling.h:118
ReflectiveRapidJSON::JsonDeserializationError::member
const char * member
The name of the member which was being processed when the error was ascertained.
Definition
errorhandling.h:122
ReflectiveRapidJSON::JsonDeserializationError::record
const char * record
The name of the class or struct which was being processed when the error was ascertained.
Definition
errorhandling.h:120
ReflectiveRapidJSON::JsonDeserializationError::noIndex
static constexpr std::size_t noIndex
Indicates no array was being processed when the error occurred.
Definition
errorhandling.h:127
ReflectiveRapidJSON::JsonDeserializationError::kind
JsonDeserializationErrorKind kind
Which kind of error occurred.
Definition
errorhandling.h:114
Generated on
for Reflection for RapidJSON by
1.18.0