Luncher91 / A2LParser

Java library to parse A2L files into an easy to use object structure.
MIT License
34 stars 13 forks source link

JsonParseException when running example from readme #22

Closed bavovanachte closed 2 years ago

bavovanachte commented 2 years ago

Hi,

Your project peaked my interest and I'd like it to try to generate a2l files out of existing json files. I was trying out the example in the readme, but when issuing the following command:

$ java -jar a2lparser-2.4.1-jar-with-dependencies.jar --json ~/Projects/git/A2LParser/src/test/resources/freeTest.a2l 

The following error is generated:

Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)
 at [Source: (File); line: 1, column: 5]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2391)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:735)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:659)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipComment(UTF8StreamJsonParser.java:3210)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd2(UTF8StreamJsonParser.java:3090)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd(UTF8StreamJsonParser.java:3046)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:756)
    at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4761)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4667)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3494)
    at net.alenzen.a2l.Asap2File.fromJsonFile(Asap2File.java:173)
    at net.alenzen.a2l.Asap2Parser.main(Asap2Parser.java:336)

I took the jar from the releases page

Luncher91 commented 2 years ago

Hi Bavo,

Thank you for pointing that out. I actually had an issue in these commands. It should be '--asap2' instead of '--json' to convert an a2l to a json file. I corrected that in the README.md

But in order to generate a a2l file from a json file you need either to specify the path to the json file with the --json parameter or pipe the content via stdout/in by omitting the path.

Example: java -jar a2lparser-2.4.1-jar-with-dependencies.jar --json anyValidJsonFile.json

The command prints the a2l file to the console. You can also specify an output file adding -o output.a2l

I hope that helps you out here.

Kind regard, Andreas