Changes between Version 11 and Version 12 of pyson


Ignore:
Timestamp:
04/21/21 22:16:43 (4 years ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pyson

    v11 v12  
    1919The basic version determines the types for (de)serialization from the __init__ function in the involved classes. Polymorphism is supported, so derived classes can (de)serialized from a superclass.
    2020
    21 A complex example showing many things at once (I did not have time to write out many simpler examples)
     21== Examples
     22
     23See [source:packson3/test/ObjectMapperTest.py] for many examples.
     24
     25A simple example, deserializng a dict with objects
     26{{{
     27from packson3.ObjectMapper import ObjectMapper
     28from packson3.JsonTypeInfo import JsonTypeInfo
     29from packson3.JsonTypeInfo import Id,As
     30
     31@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
     32class Simple:
     33    def __init__(self, a:int):
     34        self._a=a
     35    def geta(self)->int:
     36        return self._a
     37    def __eq__(self, other):
     38        return isinstance(other, self.__class__) and \
     39            self._a==other._a
     40    def __str__(self):
     41        return self._name+","+str(self._a)
     42
     43packson3=ObjectMapper()
     44objson = { 'a':{"Simple":{'a':1}},'c':{"Simple":{'a':3}}}
     45obj=packson3.parse(objson, Dict[str,Simple])
     46}}}
     47
     48
     49A complex example showing many things at once
    2250
    2351{{{