У меня есть этот кусок кода:
File jsonFile = Paths.get(jsonPath).toFile();
BufferedReader bufferedReader = new BufferedReader(new FileReader(jsonFile));
Type collectionType = new TypeToken<List<Pattern>>(){}.getType();
List<Pattern> listPatterns = new Gson().fromJson(bufferedReader, collectionType);
, когда я запускаю его на IntelliJ, он прошел успешно, но после сборки в файл JAR и запуска Spark-submit в Windows CMD он получил ошибку:
spark-submit --class com.bigdata.main.Application --master local[1] target\extraction.jar
Ошибка:
Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1
at com.google.gson.Gson.fromJson(Gson.java:815)
at com.google.gson.Gson.fromJson(Gson.java:768)
at com.bigdata.main.Application.main(Application.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:849)
at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:167)
at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:195)
at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)
at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:924)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:933)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:338)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.Gson.fromJson(Gson.java:803)
... 14 more
Мой файл JSON работает нормально в команде IntelliJ и Centos linux, но при запуске в Windows произошла ошибка.
Содержимое Json:
[
{
"bankName": "Bank1",
"Patterns": [
{
"category": "daily",
"type": "",
"pattern": "pattern_regex_1"
}
]
},
{
"bankName": "Bank2",
"Patterns": [
{
"category": "daily",
"type": "",
"pattern": "pattern_regex_2"
},
{
"category": "daily",
"type": "",
"pattern": "pattern_regex_3"
},
{
"category": "visa",
"type": "",
"pattern": "pattern_regex_4"
},
{
"category": "visa",
"type": "",
"pattern": "pattern_regex_5"
}
]
}
]
Спасибо за вашу поддержку!