@@ -171,58 +171,6 @@ fn not_example() -> Result<(), Error<u8>> {
171171}
172172```
173173
174- # JSON
175-
176- ` refined_type ` is compatible with ` serde_json ` . This ensures type-safe communication and eliminates the need to write
177- new validation processes. All you need to do is implement a set of rules once and implement ` serde ` ’s ` Serialize `
178- and ` Deserialize ` .
179-
180- ### Serialize
181-
182- ``` rust
183- #[derive(Debug , Eq , PartialEq , Deserialize , Serialize )]
184- struct Human2 {
185- name : NonEmptyString ,
186- age : u8 ,
187- }
188-
189- fn example_9 () -> anyhow :: Result <()> {
190- let john = Human2 {
191- name : NonEmptyString :: new (" john" . to_string ())? ,
192- age : 8 ,
193- };
194-
195- let actual = json! (john );
196- let expected = json! {{
197- " name" : " john" ,
198- " age" : 8
199- }};
200- assert_eq! (actual , expected );
201- Ok (())
202- }
203- ```
204-
205- ### Deserialize
206-
207- ``` rust
208- fn example_10 () -> anyhow :: Result <()> {
209- let json = json! {{
210- " name" : " john" ,
211- " age" : 8
212- }}
213- . to_string ();
214-
215- let actual = serde_json :: from_str :: <Human2 >(& json )? ;
216-
217- let expected = Human2 {
218- name : NonEmptyString :: new (" john" . to_string ())? ,
219- age : 8 ,
220- };
221- assert_eq! (actual , expected );
222- Ok (())
223- }
224- ```
225-
226174# Number
227175
228176## ` MinMax `
@@ -698,3 +646,55 @@ fn custom_length_example() -> Result<(), Error<Hello>> {
698646 Ok (())
699647}
700648```
649+
650+ # JSON
651+
652+ ` refined_type ` is compatible with ` serde_json ` . This ensures type-safe communication and eliminates the need to write
653+ new validation processes. All you need to do is implement a set of rules once and implement ` serde ` ’s ` Serialize `
654+ and ` Deserialize ` .
655+
656+ ### Serialize
657+
658+ ``` rust
659+ #[derive(Debug , Eq , PartialEq , Deserialize , Serialize )]
660+ struct Human2 {
661+ name : NonEmptyString ,
662+ age : u8 ,
663+ }
664+
665+ fn example_9 () -> anyhow :: Result <()> {
666+ let john = Human2 {
667+ name : NonEmptyString :: new (" john" . to_string ())? ,
668+ age : 8 ,
669+ };
670+
671+ let actual = json! (john );
672+ let expected = json! {{
673+ " name" : " john" ,
674+ " age" : 8
675+ }};
676+ assert_eq! (actual , expected );
677+ Ok (())
678+ }
679+ ```
680+
681+ ### Deserialize
682+
683+ ``` rust
684+ fn example_10 () -> anyhow :: Result <()> {
685+ let json = json! {{
686+ " name" : " john" ,
687+ " age" : 8
688+ }}
689+ . to_string ();
690+
691+ let actual = serde_json :: from_str :: <Human2 >(& json )? ;
692+
693+ let expected = Human2 {
694+ name : NonEmptyString :: new (" john" . to_string ())? ,
695+ age : 8 ,
696+ };
697+ assert_eq! (actual , expected );
698+ Ok (())
699+ }
700+ ```
0 commit comments