antlr / antlr4-lab

A client/server for trying out and learning about ANTLR
MIT License
39 stars 11 forks source link

Use javax.json to serialize the JSON content #57

Closed qligier closed 2 years ago

qligier commented 2 years ago

This replaces the string builders with javax.json.Json builders. It should definitively solve the escaping issues like #51 and #54.

The only functionality I've not tested is the SVG generation because I don't have all the dependencies. The rest of the response is fine and is correctly shown in the UI (to the best of my knowledge).

parrt commented 2 years ago

great! Much cleaner. thanks

parrt commented 2 years ago

Will have to back this out. As usual java libraries suck ass. Code in json lib appears broken; no doubt it's how we're using them but this code fails when you put a bad grammar in:

Screen Shot 2022-11-18 at 10 38 51 AM
        return Json.createObjectBuilder()
            .add("warnings", Json.createArrayBuilder(warnings).build())
            .add("parser_grammar_errors", Json.createArrayBuilder(parselistener.errors).build())
            .add("lexer_grammar_errors", Json.createArrayBuilder(lexlistener.errors).build())
            .add("result", result);
java.lang.IllegalArgumentException: Type class org.glassfish.json.JsonStringImpl is not supported.
    at org.glassfish.json.MapUtil.handle(MapUtil.java:112)
    at org.glassfish.json.JsonObjectBuilderImpl.populate(JsonObjectBuilderImpl.java:202)
    at org.glassfish.json.JsonObjectBuilderImpl.<init>(JsonObjectBuilderImpl.java:76)
    at org.glassfish.json.MapUtil.handle(MapUtil.java:100)
    at org.glassfish.json.JsonArrayBuilderImpl.populate(JsonArrayBuilderImpl.java:352)
    at org.glassfish.json.JsonArrayBuilderImpl.<init>(JsonArrayBuilderImpl.java:80)
    at org.glassfish.json.JsonProviderImpl.createArrayBuilder(JsonProviderImpl.java:213)
    at javax.json.Json.createArrayBuilder(Json.java:290)
    at org.antlr.v4.server.GrammarProcessor.interp(GrammarProcessor.java:103)

wasted 30 minutes trying to figure this out. I guess it's time to give my phd back. java json lib: you just made my list!

parrt commented 2 years ago

(Thanks for your efforts though...it is much cleaner but...)

I'm guessing i could build a json lib that was trivial to understand in 1 hour. People ask me why I build my own libraries...this is why.

qligier commented 2 years ago

I can't reproduce it, but I've to agree this library is particularly unpleasant to work with (and seems dependent on the runtime...).

bug

I've chosen it because the JsonReader was already used in the code. I've got better experiences with Gson, I can add it as a dependency and convert the code to the new API if you want; it shouldn't require much more work now.

parrt commented 2 years ago

hiya! If you're running that on the live server, it's running old code. (just checking)

Cool! Yes, if gson is better and we can make it work, let's do it :)