* Gets serializer for. * @param {EXPECTED_ANY} object for serialization * @returns {SerializerConfigWithSerializer} Serializer config
(object)
| 315 | * @returns {SerializerConfigWithSerializer} Serializer config |
| 316 | */ |
| 317 | static getSerializerFor(object) { |
| 318 | const proto = Object.getPrototypeOf(object); |
| 319 | /** @type {null | Constructor} */ |
| 320 | let c; |
| 321 | if (proto === null) { |
| 322 | // Object created with Object.create(null) |
| 323 | c = null; |
| 324 | } else { |
| 325 | c = proto.constructor; |
| 326 | if (!c) { |
| 327 | throw new Error( |
| 328 | "Serialization of objects with prototype without valid constructor property not possible" |
| 329 | ); |
| 330 | } |
| 331 | } |
| 332 | const config = serializers.get(c); |
| 333 | |
| 334 | if (!config) { |
| 335 | throw new Error( |
| 336 | `No serializer registered for ${/** @type {Constructor} */ (c).name}` |
| 337 | ); |
| 338 | } |
| 339 | if (config === NOT_SERIALIZABLE) throw NOT_SERIALIZABLE; |
| 340 | |
| 341 | return /** @type {SerializerConfigWithSerializer} */ (config); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Gets deserializer for. |
no test coverage detected