Skip to content

Commit

Permalink
fail at field type mismatch in json2pb
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterRK committed Apr 23, 2024
1 parent 6a335aa commit d15f67a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/json2pb/json_to_pb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,17 @@ static bool JsonValueToProtoField(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
const BUTIL_RAPIDJSON_NAMESPACE::Value & item = value[index]; \
if (TYPE_MATCH == J2PCHECKTYPE(item, cpptype, jsontype)) { \
reflection->Add##method(message, field, item.Get##jsontype()); \
} else { \
J2PERROR_WITH_PB(message, err, "Type mismatch"); \
return false; \
} \
} \
} else if (TYPE_MATCH == J2PCHECKTYPE(value, cpptype, jsontype)) { \
reflection->Set##method(message, field, value.Get##jsontype()); \
} \
} else { \
J2PERROR_WITH_PB(message, err, "Type mismatch"); \
return false; \
} \
break; \
} \

Expand Down Expand Up @@ -430,7 +436,10 @@ static bool JsonValueToProtoField(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
str = str_decoded;
}
reflection->AddString(message, field, str);
}
} else {
J2PERROR_WITH_PB(message, err, "Type mismatch");
return false;
}
}
} else if (TYPE_MATCH == J2PCHECKTYPE(value, string, String)) {
std::string str(value.GetString(), value.GetStringLength());
Expand All @@ -444,6 +453,9 @@ static bool JsonValueToProtoField(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
str = str_decoded;
}
reflection->SetString(message, field, str);
} else {
J2PERROR_WITH_PB(message, err, "Type mismatch");
return false;
}
break;

Expand Down

0 comments on commit d15f67a

Please sign in to comment.