Re:Rust 2018 survey results
by Matthias247 on Tuesday November 27, 2018 @11:42PM
(#18549336)
throwing annotations on structs and letting the library generate suitable serializers and deserializers works reasonably well in Go, as long as the JSON is not too unstructured. The same applies for Java and C# (here the JSON libs might be even better). And obviously for Rust too via serde.
Thats a fairly big restriction though and a sign of type system that is not flexible enough.
Re:Rust 2018 survey results
by Matthias247 on Wednesday November 28, 2018 @03:28PM
(#18555331)
Maybe. However your representation isn't without drawbacks either: All fields are typed by strings, and are thereby not strongly typed. And each additional level (in an array or object) requires mandatory boxing and allocations. The codegen variants on pure structs don't have this drawbacks.
I would say your representation is favorable when someone wants to work with arbitrary JSON in a flexible fashion. However if schemas and code generators are available, I would prefer to use those.
Thing is in Rust you can do both
Re:Rust 2018 survey results
by happysanta on Tuesday November 27, 2018 @06:00PM
(#18547674)
Not proficient in Go but I see an interface{} somewhere in the answer.
enum Value { Null, Bool(bool), Number(Number), String(String), Array(Vec<Value>), Object(Map<String, Value>), }
How would this look in Go?