Why from_json doesn't work for struct created with record macro?
require "json"
record Stock,
symbol : String,
name : String
p Stock.from_json %({ "symbol": "MSFT", "name": "Some" })
Error
13 | new parser
^--
Error: wrong number of arguments for 'Stock.new' (given 1, expected 2)
Overloads are:
- Stock.new(symbol : String, name : String)
Question 2:
The stack trace doesn't have the line number, I tried to use --error-trace but it had no effect, how can I use --error-trace?
> crystal api/crystal/play.cr --error-trace
Showing last frame. Use --error-trace for full trace.
In /crystal-1.1.1-1/src/json/from_json.cr:13:3
13 | new parser
^--
Error: wrong number of arguments for 'Stock.new' (given 1, expected 2)
Overloads are:
- Stock.new(symbol : String, name : String)
P.S.
I found solution, although would be better if it just worked, without the need to include JSON::Serializable
record Stock,
symbol : String,
name : String,
do
include JSON::Serializable
end