Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update json.h #199

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cpp/runtime/include/adl/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void ignore( JsonReader &json );
inline bool
matchField0( const std::string &f, JsonReader &json )
{
if( json.type() != JsonReader::FIELD )
if( (json.type() != JsonReader::FIELD) && (json.type() != JsonReader::NULLV) )
throw json_parse_failure("Field match failed");
bool match = json.fieldName() == f;
if( match )
Expand All @@ -168,7 +168,7 @@ template <class T>
bool
readField( typename Serialiser<T>::Ptr js, T &v, const std::string &f, JsonReader &json )
{
if( json.type() != JsonReader::FIELD )
if( (json.type() != JsonReader::FIELD) && (json.type() != JsonReader::NULLV) )
throw json_parse_failure("readField failed");
if( json.fieldName() != f )
return false;
Expand Down Expand Up @@ -394,12 +394,23 @@ class OptionalSerialiser : public Serialiser<std::optional<V>>

void toJson( JsonWriter &json, const _O & v ) const
{
// implement
if (v.has_value()) {
js()->toJson(json, v.value());
} else {
js()->toJson(json, nullptr);
}
}

void fromJson( _O &optional, JsonReader &json ) const
{
// implement
if (json.type() == JsonReader::NULLV) {
json.next();
optional.reset();
} else {
V v;
js()->fromJson(v, json);
optional = v;
}
}

private:
Expand Down
Loading