SerializableJSONString.cpp 975 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-30
  6. * Changed: 2020-11-06
  7. *
  8. * */
  9. #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONString.hpp"
  10. ls_std::SerializableJSONString::SerializableJSONString(std::shared_ptr<ls_std::String> _value) :
  11. Class("SerializableJSONString"),
  12. value(std::move(_value))
  13. {}
  14. ls_std::byte_field ls_std::SerializableJSONString::marshal()
  15. {
  16. this->_update();
  17. return this->jsonObject.dump();
  18. }
  19. void ls_std::SerializableJSONString::unmarshal(const ls_std::byte_field& _data)
  20. {
  21. std::string jsonString = std::string(_data);
  22. this->jsonObject = nlohmann::json::parse(jsonString);
  23. if(this->jsonObject.contains("value")) {
  24. *this->value = this->jsonObject["value"];
  25. }
  26. }
  27. void ls_std::SerializableJSONString::_update()
  28. {
  29. this->jsonObject = {
  30. {"value", this->value->toString()}
  31. };
  32. }