New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing naming/functionality in JSON::Serializable #9323
Comments
The struct Results
include JSON::Serializable
@[JSON::Field(root: "data")]
property results : Array(String)
end
pp Results.from_json <<-JSON
{
"results": {
"data": [
"result1", "result2"
],
"offset": 0,
"total_size": 1
}
}
JSON
You instead want to essentially unfold nested JSON objects into different properties on the model. This is not supported by Maybe this could be made to work... as long as the combination of key and root is unique, this is fine. It just makes the deserialization more complex. |
It would be nice if it could be added. The documentation makes it sound like what I'm trying to do would work. |
|
JSON::Field
haskey
androot
. According to the docskey
is "the value of the key in the json object" androot
should "assume the value is inside a JSON object with a given key". Idk what I'm doing wrong, but it doesn't seem like they work as expected together. Take the following example:According to the documentation I would expect the above to require
key: "english"
androot: "name"
, but that doesn't work. Unfortunately this method doesn't work if you have multiples of the same key. The actual data looks like this:which with the current API would require a model that looks like this:
which won't work because of the duplicate keys.
Hopefully I'm explaining the issue well enough. Here's a carc.in showing the problem in action https://carc.in/#/r/93rz.
The text was updated successfully, but these errors were encountered: