hololinked.serializers.serializers.Serializers
A singleton class that holds all serializers and provides a registry for content types. All members are class attributes.
- For property, the value is serialized using the serializer registered for the property.
- For action, the return value is serialized using the serializer registered for the action.
- For event, the payload is serialized using the serializer registered for the event.
Registration of serializer is not mandatory for any property, action or event.
The default serializer is JSONSerializer
, which will be provided to any unregistered object.
Source code in hololinked\serializers\serializers.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
|
Functions
for_object
classmethod
Retrieve a serializer for a given property, action or event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
the id of the Thing or the Thing that owns the property, action or event |
required | |
|
str
|
the name of the property, action or event |
required |
Returns:
Type | Description |
---|---|
BaseSerializer | JSONSerializer
|
the serializer for the property, action or event. If no serializer is found, the default JSONSerializer is returned. |
Source code in hololinked\serializers\serializers.py
register
classmethod
Register a new serializer. It is recommended to implement a content type property/attribute for the serializer to facilitate automatic deserialization on client side, otherwise deserialization is not gauranteed by this package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
BaseSerializer
|
the serializer to register |
required |
|
str | None
|
the name of the serializer to be accessible under the object namespace. If not provided, the name of the serializer class is used. |
None
|
|
bool
|
whether to override the serializer if the content type is already registered, by default False & raises ValueError for duplicate content type. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
if the serializer content type is already registered |
Source code in hololinked\serializers\serializers.py
register_content_type_for_object
classmethod
Register content type for a property, action, event, or a Thing
class to use a specific serializer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
the property, action or event. string is not accepted - use |
required |
|
str
|
the content type for the value of the objekt or the serializer to be used |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if the object is not a Property, Action or Event |
Source code in hololinked\serializers\serializers.py
register_for_object
classmethod
Register (an existing) serializer for a property, action or event. Other option is to register a content type, the effects are similar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
the property, action or event |
required |
|
BaseSerializer
|
the serializer to be used |
required |
Source code in hololinked\serializers\serializers.py
Attributes
json
: JSONSerializer
class-attribute
, writable
The default serializer for all properties, actions and events (msgspec
based C++ implementation)
pickle
: PickleSerializer
class-attribute
, writable
pickle serializer, unsafe without encryption but useful for faster & flexible serialization of python specific types
msgpack
: MsgPackSerializer
class-attribute
, writable
MessagePack serializer, efficient binary format that is both fast & interoperable between languages but not human readable
default
: BaseSerializer
class-attribute
, writable
JSONSerializer
, set it to use something else