@@ -361,7 +361,7 @@ impl<'a> Serialize for ArraySerializer<'a> {
361
361
mod tests {
362
362
use crate as bevy_reflect;
363
363
use crate :: serde:: ReflectSerializer ;
364
- use crate :: { Reflect , ReflectSerialize , TypeRegistry } ;
364
+ use crate :: { FromReflect , Reflect , ReflectSerialize , TypeRegistry } ;
365
365
use bevy_utils:: HashMap ;
366
366
use ron:: ser:: PrettyConfig ;
367
367
use serde:: Serialize ;
@@ -371,6 +371,7 @@ mod tests {
371
371
struct MyStruct {
372
372
primitive_value : i8 ,
373
373
option_value : Option < String > ,
374
+ option_value_complex : Option < SomeStruct > ,
374
375
tuple_value : ( f32 , usize ) ,
375
376
list_value : Vec < i32 > ,
376
377
array_value : [ i32 ; 5 ] ,
@@ -384,7 +385,7 @@ mod tests {
384
385
custom_serialize : CustomSerialize ,
385
386
}
386
387
387
- #[ derive( Reflect , Debug , PartialEq , Serialize ) ]
388
+ #[ derive( Reflect , FromReflect , Debug , PartialEq ) ]
388
389
struct SomeStruct {
389
390
foo : i64 ,
390
391
}
@@ -400,6 +401,11 @@ mod tests {
400
401
Struct { foo : String } ,
401
402
}
402
403
404
+ #[ derive( Reflect , Debug , PartialEq , Serialize ) ]
405
+ struct SomeSerializableStruct {
406
+ foo : i64 ,
407
+ }
408
+
403
409
/// Implements a custom serialize using `#[reflect(Serialize)]`.
404
410
///
405
411
/// For testing purposes, this just uses the generated one from deriving Serialize.
@@ -408,7 +414,7 @@ mod tests {
408
414
struct CustomSerialize {
409
415
value : usize ,
410
416
#[ serde( rename = "renamed" ) ]
411
- inner_struct : SomeStruct ,
417
+ inner_struct : SomeSerializableStruct ,
412
418
}
413
419
414
420
fn get_registry ( ) -> TypeRegistry {
@@ -417,6 +423,8 @@ mod tests {
417
423
registry. register :: < SomeStruct > ( ) ;
418
424
registry. register :: < SomeTupleStruct > ( ) ;
419
425
registry. register :: < CustomSerialize > ( ) ;
426
+ registry. register :: < SomeSerializableStruct > ( ) ;
427
+ registry. register_type_data :: < SomeSerializableStruct , ReflectSerialize > ( ) ;
420
428
registry. register :: < String > ( ) ;
421
429
registry. register :: < Option < String > > ( ) ;
422
430
registry. register_type_data :: < Option < String > , ReflectSerialize > ( ) ;
@@ -431,6 +439,7 @@ mod tests {
431
439
let input = MyStruct {
432
440
primitive_value : 123 ,
433
441
option_value : Some ( String :: from ( "Hello world!" ) ) ,
442
+ option_value_complex : Some ( SomeStruct { foo : 123 } ) ,
434
443
tuple_value : ( PI , 1337 ) ,
435
444
list_value : vec ! [ -2 , -1 , 0 , 1 , 2 ] ,
436
445
array_value : [ -2 , -1 , 0 , 1 , 2 ] ,
@@ -445,7 +454,7 @@ mod tests {
445
454
} ,
446
455
custom_serialize : CustomSerialize {
447
456
value : 100 ,
448
- inner_struct : SomeStruct { foo : 101 } ,
457
+ inner_struct : SomeSerializableStruct { foo : 101 } ,
449
458
} ,
450
459
} ;
451
460
@@ -462,6 +471,11 @@ mod tests {
462
471
"bevy_reflect::serde::ser::tests::MyStruct": {
463
472
"primitive_value": 123,
464
473
"option_value": Some("Hello world!"),
474
+ "option_value_complex": {
475
+ "Some": ({
476
+ "foo": 123,
477
+ }),
478
+ },
465
479
"tuple_value": (3.1415927, 1337),
466
480
"list_value": [
467
481
-2,
0 commit comments