Closed ghost closed 6 months ago
Just data?
Just data?
I think so.
JSON elements would have to map to the existing Collection
classes.
JSON elements would have to map to the existing
Collection
classes.
https://github.com/objeck/objeck-lang/issues/421 https://github.com/objeck/objeck-lang/issues/422
For clarity, the code must use an existing JSON parser and return associated collections.
Mapping:
Hash
Vector
String
BoolRef
FloatRef
Nil
All of the above types are supported in the JsonElement
class, so the ask is really to map the JsonElement to the internal collections it uses.
I will defer this; it seems like a "nice to have," which I do have time to implement. Please, refer to the prior comment.
After looking into this more...
What about type-checking? Generate an exception if the wrong data type is cast?
The existing JsonElement
class supports a type and a value. In dynamically typed languages, a value is a type/value. However, a value must map to a type in statically typed languages, which requires runtime type checking.
What is your proposed solution?
After looking into this more...
What about type-checking? Generate an exception if the wrong data type is cast?
The existing
JsonElement
class supports a type and a value. In dynamically typed languages, a value is a type/value. However, a value must map to a type in statically typed languages, which requires runtime type checking.What is your proposed solution?
Does Objeck support Reflection
? What does System.Introspection
do?
Does Objeck support something equivalent?
https://www.geeksforgeeks.org/typeof-operator-keyword-in-c-sharp/
Btw, yes, this is the advantage of a language that supports exceptions. Everything is so much easier with exceptions.
https://code-maze.com/csharp-how-to-ensure-a-string-is-valid-json/
I know you will never add support for exceptions, so I will close this.
Objeck supports reflection via the System.Introspection
class; however, that is not tied to supporting exceptions. In my professional experience, most developers either log or throw exceptions versus writing proper error-handling routines.
Please refer to the code below. I don't think parsing JSON into Collection
classes is beneficial in Objeck since it is a strongly typed language. The cast statements are distracting.
With Collections
root := JsonParser->New(document)<Base>;
if(root <> Nil) {
success := root->As(Map)->Find("success");
if(success <> Nil) {
success->As(String)->Equals("true")->PrintLine();
};
};
With JsonElement
parser := JsonParser->New(document);
if(parser->Parse()) {
root := parser->GetRoot();
success := root->Get("success");
if(success <> Nil) {
success->GetString()->Equals("true")->PrintLine();
};
};
The idea is to be able to send/receive Objeck objects between processes, over the network,...