SerializableJSONBoolean.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-04
  6. * Changed: 2020-11-25
  7. *
  8. * */
  9. #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONBoolean.hpp"
  10. #include <ls_std/exception/IllegalArgumentException.hpp>
  11. ls_std::SerializableJSONBoolean::SerializableJSONBoolean(const std::shared_ptr<ls_std::Boolean>& _value) :
  12. Class("SerializableJSONBoolean")
  13. {
  14. this->_assignValue(_value);
  15. }
  16. ls_std::byte_field ls_std::SerializableJSONBoolean::marshal()
  17. {
  18. this->_update();
  19. return this->jsonObject.dump();
  20. }
  21. void ls_std::SerializableJSONBoolean::unmarshal(const ls_std::byte_field& _data)
  22. {
  23. this->jsonObject = nlohmann::json::parse(_data);
  24. if(this->jsonObject.contains("value")) {
  25. *this->value = (bool) this->jsonObject["value"];
  26. }
  27. }
  28. void ls_std::SerializableJSONBoolean::_assignValue(const std::shared_ptr<ls_std::Boolean> &_value)
  29. {
  30. if(_value == nullptr) {
  31. throw ls_std::IllegalArgumentException {};
  32. }
  33. this->value = _value;
  34. }
  35. void ls_std::SerializableJSONBoolean::_update()
  36. {
  37. this->jsonObject = {
  38. {"value", this->value->getValue()}
  39. };
  40. }