0

I'm running some analysis tools in Java for my WES analysis. So, I can be considered as a newbie in Java :( Btw, I use PharmCAT to analyse my VCF file. but I got this error:

com.google.gson.JsonSyntaxException: Apr 24, 2018 12:00:00 AM

I've found a topic asking about this error but due to my limitation in Java, I don't know how to fix my problem. Here is my command:

$ java -cp PharmCAT/build/pharmcat-0.7.0-all.jar org.pharmgkb.pharmcat.haplotype.NamedAlleleMatcher -vcf path/to/my/vcf -json output.json

Its traceback:

com.google.gson.JsonSyntaxException: Apr 24, 2018 12:00:00 AM
    at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:74)
    at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:59)
    at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:41)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
    at com.google.gson.Gson.fromJson(Gson.java:887)
    at com.google.gson.Gson.fromJson(Gson.java:825)
    at org.pharmgkb.pharmcat.util.DataSerializer.deserializeDefinitionsFromJson(DataSerializer.java:61)
    at org.pharmgkb.pharmcat.haplotype.DefinitionReader.readFile(DefinitionReader.java:103)
    at org.pharmgkb.pharmcat.haplotype.DefinitionReader.read(DefinitionReader.java:90)
    at org.pharmgkb.pharmcat.haplotype.NamedAlleleMatcher.main(NamedAlleleMatcher.java:96)
Caused by: java.text.ParseException: Failed to parse date [“Apr 24, 2018 12:00:00 AM’]: Invalid number: Apr 
    at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:274)
    at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:72)
    ... 10 more
Caused by: java.lang.NumberFormatException: Invalid number: Apr 
    at com.google.gson.internal.bind.util.ISO8601Utils.parseInt(ISO8601Utils.java:311)
    at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:129)
    ... 11 more

Can anyone help me point out the problem with an instruction to fix it? Thanks for your consideration.

  • `Failed to parse date [“Apr 24, 2018 12:00:00 AM’]: Invalid number: Apr` is a pretty clear statement which tells you that the pattern used for parsing the date is not the one the date `String` has. Can you show us the Java code that parses the date? – deHaar Jan 06 '20 at 09:19
  • import java.io.IOException; import java.lang.invoke.MethodHandles; import java.nio.file.Files; import java.nio.file.Path; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.google.common.base.Preconditions; – Nga Thu Phan Võ Jan 07 '20 at 03:02

2 Answers2

0

You need to create a JsonDeserializer where you will give specific date format, Like below

GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Date.class, new DateDeserializer());

Try this link : Here is one example

Jitendra
  • 70
  • 5
  • Thank you. But it isn't clear for me :( that means I need to create a JSON file and put in my tool folder? Or just add those lines in my tool.java file? – Nga Thu Phan Võ Jan 08 '20 at 03:00
  • Create a class DateDeserializer.java, as in given link, and object of this class will be passed to GsonBuilder, now this class will be used to deserialized the date, which will be able to understand you date format. – Jitendra Jan 08 '20 at 10:12
  • Yep, I got it and came over my problem! – Nga Thu Phan Võ Jan 09 '20 at 09:11
0

I had exactly same issue. PharmCAT requires java 1.8 and needs JDK 8. My java version was 11 and could not parse some info from pharmcat jar file. Try to download right version of JDK and run jar file, it will work. Hope that helps