Skip to content
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

Null fields in JSON deserialization (lang::json::IO) #1950

Open
tvdstorm opened this issue May 21, 2024 · 0 comments
Open

Null fields in JSON deserialization (lang::json::IO) #1950

tvdstorm opened this issue May 21, 2024 · 0 comments
Labels

Comments

@tvdstorm
Copy link
Member

Apparently, null fields in JSON are ignored (or trigger exceptions):

rascal>import lang::json::IO;
rascal>parseJSON(#value, "{\"a\": null}");
value: "object"()
rascal>parseJSON(#value, "{\"a\": 2}");
value: "object"(
 a=2)

With an explicit type, it triggers an exception:

rascal>data Foo = foo(int a=-1);
ok
rascal>parseJSON(#Foo, "{\"a\": 2}");
Foo: foo(a=2)
rascal>parseJSON(#Foo, "{\"a\": null}");
|std:///lang/json/IO.rsc|(2599,303,<49,0>,<52,144>): Java("IllegalStateException","Expected a name but was NULL at line 1 column 11 path $.a")
        at com.google.gson.stream.JsonReader.nextName(|unknown:///JsonReader.java|(0,0,<800,0>,<800,0>))
        at org.rascalmpl.library.lang.json.internal.JsonValueReader$2.visitAbstractData(|unknown:///JsonValueReader.java|(0,0,<517,0>,<517,0>))
        at org.rascalmpl.library.lang.json.internal.JsonValueReader$2.visitAbstractData(|unknown:///JsonValueReader.java|(0,0,<116,0>,<116,0>))
        at io.usethesource.vallang.type.AbstractDataType.accept(|unknown:///AbstractDataType.java|(0,0,<422,0>,<422,0>))
        at org.rascalmpl.library.lang.json.internal.JsonValueReader.read(|unknown:///JsonValueReader.java|(0,0,<116,0>,<116,0>))
        at org.rascalmpl.library.lang.json.IO.parseJSON(|unknown:///IO.java|(0,0,<130,0>,<130,0>))
        at parseJSON(|std:///lang/json/IO.rsc|(2895,5,<52,137>,<52,142>)ok
@tvdstorm tvdstorm added the bug label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant