json
xsdata.formats.dataclass.serializers.json
DictFactory
Dictionary factory types.
Source code in xsdata/formats/dataclass/serializers/json.py
27 28 29 30 |
|
JsonSerializer
dataclass
Bases: AbstractSerializer
Json serializer for data classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | SerializerConfig | The serializer config instance | field(default_factory=SerializerConfig) |
context | XmlContext | The models context instance | field(default_factory=XmlContext) |
dict_factory | Callable | Dictionary factory | field(default=dict) |
dump_factory | Callable | Json dump factory e.g. json.dump | field(default=dump) |
Source code in xsdata/formats/dataclass/serializers/json.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
render(obj)
Serialize the input model instance to json string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The input model instance | required |
Returns:
Type | Description |
---|---|
str | The serialized json string output. |
Source code in xsdata/formats/dataclass/serializers/json.py
49 50 51 52 53 54 55 56 57 58 59 60 |
|
write(out, obj)
Serialize the given object to the output text stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out | TextIO | The output text stream | required |
obj | Any | The input model instance to serialize | required |
Source code in xsdata/formats/dataclass/serializers/json.py
62 63 64 65 66 67 68 69 70 71 72 73 |
|
convert(value, var=None)
Convert a value to json serializable object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Any | The input value | required |
var | Optional[XmlVar] | The xml var instance | None |
Returns:
Type | Description |
---|---|
Any | The converted json serializable value. |
Source code in xsdata/formats/dataclass/serializers/json.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
next_value(obj)
Fetch the next value of a model instance to convert.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The input model instance | required |
Yields:
Type | Description |
---|---|
str | An iterator of field name and value tuples. |
Source code in xsdata/formats/dataclass/serializers/json.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
filter_none(x)
Convert a key-value pairs to dict, ignoring None values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Tuple | Key-value pairs | required |
Returns:
Type | Description |
---|---|
Dict | The filtered dictionary. |
Source code in xsdata/formats/dataclass/serializers/json.py
15 16 17 18 19 20 21 22 23 24 |
|