Replies: 4 comments
-
Excellent point about the long-term viability of serializing enums as ints. |
Beta Was this translation helpful? Give feedback.
0 replies
-
C# also does encode and decode of enums with strings. |
Beta Was this translation helpful? Give feedback.
0 replies
-
yeah sounds good |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature
Currently both
json
andx.json2
serialize enums as integers. But it creates a problem when deserializing these values when the order of values of the enum changes - which can happen when devs change the order by sorting or add a new value in the beginning of enums.Use Case
Please see this example. If
MyEnum
is created asenum MyEnum {foo bar}
, then we generate a json from that. Later someone changes the order toenum MyEnum {bar foo}
. Then the value of parsed enum is different.Proposed Solution
Instead of integers, vlang can serialize enums as strings, e.g.
Other Information
It also requires some changes to how enums work. There must be a way of creating enum value from strings.
example:
Acknowledgements
Version used
0.3.3
Environment details (OS name and version, etc.)
OS: macos, macOS, 13.1, 22C65
Processor: 8 cpus, 64bit, little endian, Apple M1 Pro
CC version: Apple clang version 14.0.0 (clang-1400.0.29.202)
getwd: /Users/zhomart/vlang
vmodules: /Users/zhomart/.vmodules
vroot: /Users/zhomart/vlang
vexe: /Users/zhomart/vlang/v
vexe mtime: 2023-03-04 22:33:40
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 1a48d08
Git version: git version 2.39.0
Git vroot status: weekly.2022.49-500-g1a48d08d
.git/config present: true
thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0
Beta Was this translation helpful? Give feedback.
All reactions