digitalmars.D - Vibe.d - Custom serialization policy
- Flying-Toast (12/12) Jun 26 2019 I am using vibe.d's serialization feature for a few classes.
- Flying-Toast (2/15) Jun 26 2019 Also, how do I make the serializer ignore a single field?
- =?UTF-8?Q?S=c3=b6nke_Ludwig?= (9/28) Jun 26 2019 There is an example that applies a custom policy to any struct that has
- Flying-Toast (4/35) Jun 26 2019 How would I make a new policy to allow immutable/const members to
I am using vibe.d's serialization feature for a few classes. I have found that immutable/const fields are not serialized, though it turns out this is intentional [1]. In the GitHub issue [1], Sönke mentioned that a solution to this would be to use a custom `Policy`. I tried to find documentation on vibe's serialization policies, but I couldn't find any. Could anyone point me to some documentation for serialization policies, or explain how to create a policy that allows serializing immutable fields (and how to use it with the Json serializer)? [1](https://github.com/vibe-d/vibe.d/issues/1536) Thanks!
Jun 26 2019
On Wednesday, 26 June 2019 at 18:54:05 UTC, Flying-Toast wrote:I am using vibe.d's serialization feature for a few classes. I have found that immutable/const fields are not serialized, though it turns out this is intentional [1]. In the GitHub issue [1], Sönke mentioned that a solution to this would be to use a custom `Policy`. I tried to find documentation on vibe's serialization policies, but I couldn't find any. Could anyone point me to some documentation for serialization policies, or explain how to create a policy that allows serializing immutable fields (and how to use it with the Json serializer)? [1](https://github.com/vibe-d/vibe.d/issues/1536) Thanks!Also, how do I make the serializer ignore a single field?
Jun 26 2019
Am 26.06.2019 um 21:06 schrieb Flying-Toast:On Wednesday, 26 June 2019 at 18:54:05 UTC, Flying-Toast wrote:There is an example that applies a custom policy to any struct that has "x"/"y" fields: http://vibed.org/api/vibe.data.serialization/serializeWithPolicy When working with multiple policies, ChainedPolicy is also handy: http://vibed.org/api/vibe.data.serialization/ChainedPolicyI am using vibe.d's serialization feature for a few classes. I have found that immutable/const fields are not serialized, though it turns out this is intentional [1]. In the GitHub issue [1], Sönke mentioned that a solution to this would be to use a custom `Policy`. I tried to find documentation on vibe's serialization policies, but I couldn't find any. Could anyone point me to some documentation for serialization policies, or explain how to create a policy that allows serializing immutable fields (and how to use it with the Json serializer)? [1](https://github.com/vibe-d/vibe.d/issues/1536) Thanks!Also, how do I make the serializer ignore a single field?If no policy is used to serialize the particular type, the ` ignore` attribute can be applied to the field: http://vibed.org/api/vibe.data.serialization/ignore
Jun 26 2019
On Wednesday, 26 June 2019 at 21:07:34 UTC, Sönke Ludwig wrote:Am 26.06.2019 um 21:06 schrieb Flying-Toast:How would I make a new policy to allow immutable/const members to be serialized, but leave everything else as it is in DefaultPolicy?On Wednesday, 26 June 2019 at 18:54:05 UTC, Flying-Toast wrote:There is an example that applies a custom policy to any struct that has "x"/"y" fields: http://vibed.org/api/vibe.data.serialization/serializeWithPolicy When working with multiple policies, ChainedPolicy is also handy: http://vibed.org/api/vibe.data.serialization/ChainedPolicyI am using vibe.d's serialization feature for a few classes. I have found that immutable/const fields are not serialized, though it turns out this is intentional [1]. In the GitHub issue [1], Sönke mentioned that a solution to this would be to use a custom `Policy`. I tried to find documentation on vibe's serialization policies, but I couldn't find any. Could anyone point me to some documentation for serialization policies, or explain how to create a policy that allows serializing immutable fields (and how to use it with the Json serializer)? [1](https://github.com/vibe-d/vibe.d/issues/1536) Thanks!Also, how do I make the serializer ignore a single field?If no policy is used to serialize the particular type, the ` ignore` attribute can be applied to the field: http://vibed.org/api/vibe.data.serialization/ignore
Jun 26 2019