@@ -28,7 +28,7 @@ use serde::{
28
28
DeserializeSeed , Deserializer , EnumAccess , Error , Expected , IntoDeserializer ,
29
29
Unexpected as Unexp , VariantAccess , Visitor ,
30
30
} ,
31
- forward_to_deserialize_any , Deserialize ,
31
+ Deserialize ,
32
32
} ;
33
33
34
34
impl < ' de > Deserialize < ' de > for BoltType {
@@ -655,13 +655,46 @@ impl<'de> Deserializer<'de> for BoltTypeDeserializer<'de> {
655
655
}
656
656
657
657
fn deserialize_any < V > ( self , visitor : V ) -> Result < V :: Value , Self :: Error >
658
+ where
659
+ V : Visitor < ' de > ,
660
+ {
661
+ match self . value {
662
+ BoltType :: String ( _) => self . deserialize_str ( visitor) ,
663
+ BoltType :: Boolean ( _) => self . deserialize_bool ( visitor) ,
664
+ BoltType :: Map ( _)
665
+ | BoltType :: Node ( _)
666
+ | BoltType :: Relation ( _)
667
+ | BoltType :: UnboundedRelation ( _)
668
+ | BoltType :: Path ( _)
669
+ | BoltType :: Point2D ( _)
670
+ | BoltType :: Point3D ( _) => self . deserialize_map ( visitor) ,
671
+ BoltType :: Null ( _) => self . deserialize_unit ( visitor) ,
672
+ BoltType :: Integer ( _) => self . deserialize_i64 ( visitor) ,
673
+ BoltType :: Float ( _) => self . deserialize_f64 ( visitor) ,
674
+ BoltType :: List ( _) | BoltType :: Bytes ( _) => self . deserialize_seq ( visitor) ,
675
+ BoltType :: Date ( _)
676
+ | BoltType :: Time ( _)
677
+ | BoltType :: LocalTime ( _)
678
+ | BoltType :: DateTime ( _)
679
+ | BoltType :: LocalDateTime ( _)
680
+ | BoltType :: DateTimeZoneId ( _) => self . deserialize_string ( visitor) ,
681
+ BoltType :: Duration ( _) => self . deserialize_newtype_struct ( "" , visitor) ,
682
+ }
683
+ }
684
+
685
+ fn deserialize_char < V > ( self , visitor : V ) -> Result < V :: Value , Self :: Error >
658
686
where
659
687
V : Visitor < ' de > ,
660
688
{
661
689
self . unexpected ( visitor)
662
690
}
663
691
664
- forward_to_deserialize_any ! { char identifier }
692
+ fn deserialize_identifier < V > ( self , visitor : V ) -> Result < V :: Value , Self :: Error >
693
+ where
694
+ V : Visitor < ' de > ,
695
+ {
696
+ self . unexpected ( visitor)
697
+ }
665
698
666
699
fn is_human_readable ( & self ) -> bool {
667
700
true
@@ -2190,4 +2223,37 @@ mod tests {
2190
2223
2191
2224
assert_eq ! ( actual. my_string. 0 , "Frobnicate" ) ;
2192
2225
}
2226
+
2227
+ #[ test]
2228
+ fn deserialize_into_serde_json ( ) {
2229
+ let actual = [
2230
+ ( "age" . into ( ) , 42 . into ( ) ) ,
2231
+ ( "awesome" . into ( ) , true . into ( ) ) ,
2232
+ ( "values" . into ( ) , vec ! [ 13.37 , 42.84 ] . into ( ) ) ,
2233
+ (
2234
+ "nested" . into ( ) ,
2235
+ BoltType :: Map ( [ ( "key" . into ( ) , "value" . into ( ) ) ] . into_iter ( ) . collect ( ) ) ,
2236
+ ) ,
2237
+ ( "payload" . into ( ) , b"Hello, World!" . as_slice ( ) . into ( ) ) ,
2238
+ ( "secret" . into ( ) , BoltType :: Null ( BoltNull ) ) ,
2239
+ ]
2240
+ . into_iter ( )
2241
+ . collect :: < BoltMap > ( ) ;
2242
+
2243
+ let actual = BoltType :: Map ( actual) ;
2244
+ let actual = actual. to :: < serde_json:: Value > ( ) . unwrap ( ) ;
2245
+
2246
+ let expected = serde_json:: json!( {
2247
+ "age" : 42 ,
2248
+ "awesome" : true ,
2249
+ "values" : [ 13.37 , 42.84 ] ,
2250
+ "nested" : {
2251
+ "key" : "value" ,
2252
+ } ,
2253
+ "payload" : [ 72 , 101 , 108 , 108 , 111 , 44 , 32 , 87 , 111 , 114 , 108 , 100 , 33 ] ,
2254
+ "secret" : null,
2255
+ } ) ;
2256
+
2257
+ assert_eq ! ( actual, expected) ;
2258
+ }
2193
2259
}
0 commit comments