* Serializes the field value to a JSON serializable value. * @override * @throws {Error} If field value is invalid. * @throws {Error} If serialization is not possible. * @return {mixed} Serialized data
()
| 355 | * @return {mixed} Serialized data |
| 356 | */ |
| 357 | serializeValue () { |
| 358 | if (!this.isValid()) { |
| 359 | throw new Error('Invalid field values can\'t be serialized.') |
| 360 | } |
| 361 | const value = this.getValue() |
| 362 | if ( |
| 363 | typeof value !== 'boolean' && |
| 364 | typeof value !== 'number' && |
| 365 | typeof value !== 'string' && |
| 366 | value !== null |
| 367 | ) { |
| 368 | throw new Error( |
| 369 | 'Field value serialization is not possible. Generic fields can ' + |
| 370 | 'only serialize boolean, number, string or null values safely. ' + |
| 371 | `Received value type '${typeof value}'.`) |
| 372 | } |
| 373 | return value |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Extracts value serialized by {@link Field.serializeValue} and applies |
no test coverage detected