Skip to content

Commit 5e9a660

Browse files
Fixed return type
1 parent b63c246 commit 5e9a660

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

include/rfl/json/read.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <istream>
77
#include <string>
88

9+
#include "../internal/wrap_in_rfl_array_t.hpp"
910
#include "Parser.hpp"
1011
#include "Reader.hpp"
1112

@@ -24,9 +25,12 @@ auto read(const InputVarType& _obj) {
2425

2526
/// Parses an object from JSON using reflection.
2627
template <class T>
27-
auto read(const std::string& _json_str) {
28+
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _json_str) {
2829
using PtrType = std::unique_ptr<yyjson_doc, void (*)(yyjson_doc*)>;
2930
yyjson_doc* doc = yyjson_read(_json_str.c_str(), _json_str.size(), 0);
31+
if (!doc) {
32+
return Error("Could not parse document!");
33+
}
3034
const auto ptr = PtrType(doc, yyjson_doc_free);
3135
return read<T>(InputVarType(yyjson_doc_get_root(doc)));
3236
}

include/rfl/xml/read.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ auto read(const InputVarType& _var) {
2424

2525
/// Parses an object from XML using reflection.
2626
template <class T>
27-
auto read(const std::string& _xml_str) {
27+
Result<T> read(const std::string& _xml_str) {
2828
pugi::xml_document doc;
2929
const auto result = doc.load_string(_xml_str.c_str());
3030
if (!result) {

include/rfl/yaml/read.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <istream>
77
#include <string>
88

9+
#include "../internal/wrap_in_rfl_array_t.hpp"
910
#include "Parser.hpp"
1011
#include "Reader.hpp"
1112

@@ -23,7 +24,7 @@ auto read(const InputVarType& _var) {
2324

2425
/// Parses an object from YAML using reflection.
2526
template <class T>
26-
auto read(const std::string& _yaml_str) {
27+
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _yaml_str) {
2728
try {
2829
const auto var = InputVarType(YAML::Load(_yaml_str));
2930
return read<T>(var);

0 commit comments

Comments
 (0)