/**
  * Write string Value to Array or Object
  *
  * @param   string $value  Value
  * @throws \InvalidArgumentException
  * @return  bool
  */
 public function writeValue($value)
 {
     if ($this->canEdit()) {
         // If a non-scalar value is passed in (such as a class object)
         // try to convert it to string.  At this point, writeValue MUST be scalar!
         if (!is_scalar($value)) {
             try {
                 $typecast = settype($value, 'string');
             } catch (\Exception $e) {
                 throw new \InvalidArgumentException('Cannot cast non-scalar value to string (did you forget to define a __toString on your object?)', null, $e);
             }
             if ($typecast === false) {
                 throw new \InvalidArgumentException('Cannot cast non-scalar value to string (did you forget to define a __toString on your object?)');
             }
         }
         if (is_string($value)) {
             $value = $this->encodeString($value);
         }
         return $this->json->writeValue($value);
     }
     return false;
 }