Skip to content

Commit d15f67a

Browse files
committed
fail at field type mismatch in json2pb
1 parent 6a335aa commit d15f67a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/json2pb/json_to_pb.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,17 @@ static bool JsonValueToProtoField(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
334334
const BUTIL_RAPIDJSON_NAMESPACE::Value & item = value[index]; \
335335
if (TYPE_MATCH == J2PCHECKTYPE(item, cpptype, jsontype)) { \
336336
reflection->Add##method(message, field, item.Get##jsontype()); \
337+
} else { \
338+
J2PERROR_WITH_PB(message, err, "Type mismatch"); \
339+
return false; \
337340
} \
338341
} \
339342
} else if (TYPE_MATCH == J2PCHECKTYPE(value, cpptype, jsontype)) { \
340343
reflection->Set##method(message, field, value.Get##jsontype()); \
341-
} \
344+
} else { \
345+
J2PERROR_WITH_PB(message, err, "Type mismatch"); \
346+
return false; \
347+
} \
342348
break; \
343349
} \
344350

@@ -430,7 +436,10 @@ static bool JsonValueToProtoField(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
430436
str = str_decoded;
431437
}
432438
reflection->AddString(message, field, str);
433-
}
439+
} else {
440+
J2PERROR_WITH_PB(message, err, "Type mismatch");
441+
return false;
442+
}
434443
}
435444
} else if (TYPE_MATCH == J2PCHECKTYPE(value, string, String)) {
436445
std::string str(value.GetString(), value.GetStringLength());
@@ -444,6 +453,9 @@ static bool JsonValueToProtoField(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
444453
str = str_decoded;
445454
}
446455
reflection->SetString(message, field, str);
456+
} else {
457+
J2PERROR_WITH_PB(message, err, "Type mismatch");
458+
return false;
447459
}
448460
break;
449461

0 commit comments

Comments
 (0)