You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add "skip if" support for serializing dataclass fields
* Looks good, just need to add tests and docs
* Add test cases
* Update docs
* Update docs on Meta
* Add `JSONPyWizard` and some condition functions
* Add `IS_TRUTHY` and `IS_FALSY` conditions
* Add `JSONPyWizard` to skip key transformation during serialization (dump)
* update docs
* update docs
* re-order sections in docs
* update docs
* that should be v1 not v2
* Update HISTORY.rst
* Update docs
Copy file name to clipboardExpand all lines: README.rst
+159-5Lines changed: 159 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,12 +27,12 @@ Full documentation is available at `Read The Docs`_. (`Installation`_)
27
27
28
28
29
29
30
-
Dataclass Wizard offers simple, elegant, *wizarding* tools for
30
+
**Dataclass Wizard** offers simple, elegant, *wizarding* 🪄 tools for
31
31
interacting with Python's ``dataclasses``.
32
32
33
-
It excels at lightning-fast de/serialization, converting dataclass
34
-
instances to/from JSON effortlessly -- perfect for *nested dataclass*
35
-
models!
33
+
It excels at ⚡️ lightning-fast de/serialization, effortlessly
34
+
converting dataclass instances to/from JSON -- perfect for
35
+
*nested dataclass* models!
36
36
37
37
-------------------
38
38
@@ -106,8 +106,9 @@ Here are the key features that ``dataclass-wizard`` offers:
106
106
Wizard Mixins
107
107
-------------
108
108
109
-
In addition to the ``JSONWizard``, here are a few extra Mixin_ classes that might prove quite convenient to use.
109
+
In addition to ``JSONWizard``, these handy Mixin_ classes simplify your workflow:
110
110
111
+
* `JSONPyWizard`_ — A ``JSONWizard`` helper to skip *camelCase* and keep keys as-is.
111
112
* `JSONListWizard`_ -- Extends ``JSONWizard`` to return `Container`_ -- instead of *list* -- objects where possible.
112
113
* `JSONFileWizard`_ -- Makes it easier to convert dataclass instances from/to JSON files on a local drive.
113
114
* `TOMLWizard`_ -- Provides support to convert dataclass instances to/from TOML.
@@ -940,6 +941,130 @@ dataclasses in ``Union`` types. For more info, check out the
940
941
# True
941
942
assert c == c.from_json(c.to_json())
942
943
944
+
Conditional Field Skipping
945
+
--------------------------
946
+
947
+
.. admonition:: **Added in v0.30.0**
948
+
949
+
Dataclass Wizard introduces `conditional skipping`_ to omit fields during JSON serialization based on user-defined conditions. This feature works seamlessly with:
950
+
951
+
- **Global rules** via ``Meta`` settings.
952
+
- **Per-field controls** using ``SkipIf()`` `annotations`_.
953
+
- **Field wrappers** for maximum flexibility.
954
+
955
+
Quick Examples
956
+
~~~~~~~~~~~~~~
957
+
958
+
1. **Globally Skip Fields Matching a Condition**
959
+
960
+
Define a global skip rule using ``Meta.skip_if``:
961
+
962
+
.. code-block:: python3
963
+
964
+
from dataclasses import dataclass
965
+
from dataclass_wizard import JSONWizard, IS_NOT
966
+
967
+
968
+
@dataclass
969
+
class Example(JSONWizard):
970
+
class _(JSONWizard.Meta):
971
+
skip_if = IS_NOT(True) # Skip fields if the value is not `True`
0 commit comments