Commit Graph

2 Commits

Author SHA1 Message Date
Giacomo Stevanato b7b8fa4ccc TypedReflectDeserializer: return a concrete value when possible (#21137)
# Objective

- This is another way to fix to #20952
- It also fixes any other user of `TypedReflectDeserializer` that was
expecting a concrete type being returned.

## Solution

- Attempt to use the reflected `FromReflect` to produce a concrete type
after deserializing a dynamic value.

## Testing

- I added a slightly modified test from #20981 to demonstrate that this
also fixes the issue. I'll probably rebase this once #20981 lands
though.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
2025-09-21 20:42:57 +00:00
Chris Biscardi d3f9699e68 add reflection serialization example (#20940)
# Objective

It is a very common[0] misconception that serde's Serialize/Deserialize
derives are required for reflection (de)serialization. This is not true,
and can lead to unexpectedly changing the serialization behavior in a
way that doesn't get exposed via reflection information. Having an
example to point to would be a useful resource when talking about this.

[0]: This is why Avian has Serialize/Deserialize on all types, including
marker types; This also cropped up in PRs to new BRP functionality.

## Solution

Implement an example showing deserialization and serialization for a
type that only implements `Reflect`, and not serde's `Serialize` or
`Deserialize`.

## Testing

```
cargo run --example serialization
2025-09-09T19:08:28.258523Z  INFO serialization: reflect_value=DynamicStruct(serialization::Player { health: 50, name: "BevyPlayerOne" })
2025-09-09T19:08:28.258770Z  INFO serialization: player=serialization::Player { name: "BevyPlayerOne", health: 50 }
2025-09-09T19:08:28.259382Z  INFO serialization: json="{\"serialization::Player\":{\"name\":\"BevyPlayerSerialize\",\"health\":80}}"
```
2025-09-09 22:25:45 +00:00