1
votes

I want to load JSON data in Spark 2.2.2 and Java.

Dataset df = spark
                .read()
                .json(filePath);

However I get the error:

java.lang.IllegalArgumentException: Illegal pattern component: XXX
21:42:34.430 [main] INFO OntologyLoader - An error occured while loading data into the ontology.
    at org.apache.commons.lang3.time.FastDatePrinter.parsePattern(FastDatePrinter.java:282)
    at org.apache.commons.lang3.time.FastDatePrinter.init(FastDatePrinter.java:149)

This is the content of a JSON file:

{"id":"155097","sku":"CASPA0000083386","idFamily":"137","family":"Health & Beauty","idService":"135","service":"Haircut & Styling","title":"Pruebas de peinado y maquillaje de novia en Shibuy","price":"80","genderProduct":"F","socialUsage":"1","ageUsage":"2,3","dailyDeal":"true","topDeal":"false","dealFamily":"1","shortTitle":"Pelu y maquillaje Novias: Eixample","campaignName":"peinado de novia o recogido y maquillaje de novia","metaTitle":"Peluquería + maquillaje para novias en Shibuya","metaDescription":"Htest. Ofertas de belleza. Peluquería + maquillaje para novias","metaKeywords":"oferta, peluquería, maquillaje, novias, shibuya","tradeName":"Shibuya Hair Salon","featured":"<h3>Oferta para novias. ¡Únete y disfruta!</h3>\n\n<p>Tu gran día se va acercando poco a poco ¿Y tienes ya todo listo? ¿El restaurante? ¿El vestido con sus respectivas pruebas? ¿El peinado y el maquillaje? ¿Ya sabes qué te quieres hacer y dónde? ¿No? ¡Ahhh! ¿Qué estás buscando no gastaste mucho? ¡claro  es que en las  bodas son todo gastos!</p>\n\n<p>Por eso y para ayudarte, estamos en Htest  para que en tu gran día estés más guapa que nunca y no dejes de brillar,  <strong>habiéndote ahorrado más que un par de euros con este fantástico descuento.</strong></p>\n\n<p>Ven a <strong>Shibuya </strong>y hazte con:</p>\n\n<ul><li>\n\t<p><strong>Hasta 2 horas de pruebas de peinado de novia  +  hasta 2 horas de pruebas de maquillaje</strong></p>\n\t</li></ul>\n\n<p>En Shibuya Hair Salon además son asesores de la imagen y si estás perdida y no sabes lo que buscas o no lo tienes claro, en todo momento te guiarán para conseguir la imagen que más se ajusta a tu personalidad, estilo y por supuesto vestido.</p>\n\n<p>Una vez que salgas de Shibuya Hair Salón solo te podrán decir: “¡Que viva esa novia!”</p>\n\n<h3>Htest colabora con Shibuya</h3>","specialPrice":"40","discount":"50","localization":"Barcelona","address":"C/ Viladomat, 200, 08029, Barcelona","lat":"41.3846985","lon":"2.150849","isInStock":"true","active":"true","initialDateMin":"0","finalDateMax":"0","reviewScore":"0","reviewRanking":"2088","paxPerCoupon":""}

I also tried to parse JSON using a static class. but got the same error.

Encoder<Campaign> encoder = Encoders.bean(Campaign.class);
Dataset<Campaign> df = spark
                .read()
                .json(filePath)
                .as(encoder);

Just to mention that this code was working in Spark 1.6.1 with the same data. The error occurred when upgrading Spark from 1.6.1 to 2.2.2.

1
That Json is invalid an I'd be surprised if it was working in ANY Json parser. - Perdi Estaquel
@PerdiEstaquel: Have you tried to copy a JSON string from my post and paste it into any online JSON viewer?;) - ScalaBoy

1 Answers

1
votes

The error java.lang.IllegalArgumentException: Illegal pattern component: XXX is being thrown by commons-lang3 library. It looks like either you have old version of commons-lang3 dependency in your pom.xml or it is being fetched by some other dependency. Try by adding the latest version of commons-lang3 like below.

<dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.8</version>
</dependency>