From 5724c7ef6720b48556d2159dce48757ab210fe8d Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 6 Jun 2018 11:42:01 +0200 Subject: [PATCH] play around with the QString json deserializer --- src/util/rapidjson-helpers.hpp | 4 ++++ src/util/serialize-custom.hpp | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/util/rapidjson-helpers.hpp b/src/util/rapidjson-helpers.hpp index b5c6f635..a447db0a 100644 --- a/src/util/rapidjson-helpers.hpp +++ b/src/util/rapidjson-helpers.hpp @@ -73,6 +73,10 @@ bool getSafe(const rapidjson::Value &obj, const char *key, Type &out) return false; } + if (obj.IsNull()) { + return false; + } + try { out = pajlada::Settings::Deserialize::get(obj[key]); } catch (const std::runtime_error &) { diff --git a/src/util/serialize-custom.hpp b/src/util/serialize-custom.hpp index bd42bc18..e698e9a7 100644 --- a/src/util/serialize-custom.hpp +++ b/src/util/serialize-custom.hpp @@ -24,7 +24,18 @@ struct Deserialize { throw std::runtime_error("Deserialized rapidjson::Value is not a string"); } - return value.GetString(); + try { + const char *str = value.GetString(); + auto strLen = value.GetStringLength(); + + return QString::fromUtf8(str, strLen); + } catch (const std::exception &e) { + int x = 5; + } catch (...) { + int y = 5; + } + + return QString(); } };