File tree 3 files changed +20
-5
lines changed
3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 2
2
"provides" : {
3
3
"JSON::Class" : "lib/JSON/Class.pm"
4
4
},
5
- "version" : "0.0.3 ",
5
+ "version" : "0.0.4 ",
6
6
"test-depends" : [
7
7
"Test"
8
8
],
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ both serialisation and de-serialisation. The exact behaviour depends on that
33
33
of (JSON::Marshal)[ https://github.com/jonathanstowe/JSON-Marshal ] and
34
34
(JSON::Unmarshal)[ https://github.com/tadzik/JSON-Unmarshal ] respectively.
35
35
36
+
37
+ If the ``` :skip-null ``` adverb is provided to ``` to-json ``` all attributes
38
+ without a defined value will be ignored in serialisation. If you need
39
+ finer grained control then you should apply the ``` json-skip-null ```
40
+ attribute trait (defined by ``` JSON::Marshal ``` ) to the traits you
41
+ want to skip if they aren't defined (``` :json-skip ``` will still have
42
+ the same effect though.)
43
+
36
44
The (JSON::Marshal)[ https://github.com/jonathanstowe/JSON-Marshal ] and
37
45
(JSON::Unmarshal)[ https://github.com/tadzik/JSON-Unmarshal ] provide traits
38
46
for controlling the unmarshalling/marshalling of specific attributes which are
Original file line number Diff line number Diff line change @@ -58,12 +58,19 @@ type for the target class then an exception may be thrown.
58
58
59
59
= head2 method to-json
60
60
61
- method to-json() returns Str
61
+ method to-json(Bool :$skip-null ) returns Str
62
62
63
63
Serialises the public attributes of the object to a JSON string that
64
64
represents the object, this JSON can be fed to the L < from-json > of the
65
65
class to create a new object with matching (public) attributes.
66
66
67
+ If the C < :skip-null > adverb is provided all attributes without a
68
+ defined value will be ignored in serialisation. If you need finer
69
+ grained control then you should apply the C < json-skip-null > attribute
70
+ trait (defined by L < JSON::Marshal > ) to the traits you want to skip
71
+ if they aren't defined (C < :json-skip > will still have the same effect
72
+ though.)
73
+
67
74
= end pod
68
75
69
76
use JSON::Unmarshal;
@@ -73,15 +80,15 @@ sub EXPORT {
73
80
{ ' &trait_mod:<is>' => & trait_mod : <is > }
74
81
}
75
82
76
- role JSON::Class : ver<0.0.3 >: auth<github:jonathanstowe > {
83
+ role JSON::Class : ver<0.0.4 >: auth<github:jonathanstowe > {
77
84
78
85
79
86
method from-json (Str $ json ) returns JSON::Class {
80
87
unmarshal($ json , self );
81
88
}
82
89
83
- method to-json () returns Str {
84
- marshal(self );
90
+ method to-json (Bool : $ skip-null ) returns Str {
91
+ marshal(self , : $ skip-null );
85
92
}
86
93
}
87
94
You can’t perform that action at this time.
0 commit comments