Commit 65b52d888e1d355f292684c915cf77e7632c3ce5

Authored by Mickael Boiziot
1 parent c5923951
Exists in master and in 1 other branch b6.0.X

Use org.json library instead of gson to read json

pom.xml
... ... @@ -173,12 +173,11 @@
173 173  
174 174 <!-- The project dependencies -->
175 175 <dependencies>
  176 + <!-- A library to deal with JSON files -->
176 177 <dependency>
177   - <!-- A library to deal with JSON files -->
178   - <groupId>com.google.code.gson</groupId>
179   - <artifactId>gson</artifactId>
180   - <version>2.2.2</version>
181   - <scope>compile</scope>
  178 + <groupId>org.json</groupId>
  179 + <artifactId>json</artifactId>
  180 + <version>20190722</version>
182 181 </dependency>
183 182  
184 183 <!-- Needed to compile with Java 11+ as removed from Java -->
... ...
src/main/java/eu/omp/irap/vespa/votable/utils/Debug.java deleted
... ... @@ -1,72 +0,0 @@
1   -/*
2   - * This file is a part of EpnTAPClient.
3   - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
4   - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
5   - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
6   - *
7   - * This program is free software: you can
8   - * redistribute it and/or modify it under the terms of the GNU General Public License as published
9   - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
10   - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
11   - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12   - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
13   - * the GNU General Public License along with this program. If not, see
14   - * <http://www.gnu.org/licenses/>.
15   - */
16   -
17   -package eu.omp.irap.vespa.votable.utils;
18   -
19   -import java.io.FileWriter;
20   -import java.io.IOException;
21   -import java.util.logging.Logger;
22   -
23   -import com.google.gson.Gson;
24   -import com.google.gson.GsonBuilder;
25   -
26   -import eu.omp.irap.vespa.votable.Consts;
27   -
28   -/**
29   - * @author N. Jourdane
30   - */
31   -public class Debug {
32   -
33   - /** The logger for the class Debug. */
34   - private static final Logger LOGGER = Logger.getLogger(Debug.class.getName());
35   -
36   -
37   - /** Private constructor to hide the implicit public one. */
38   - private Debug() {
39   - }
40   -
41   - /**
42   - * @param object An object to serialize.
43   - * @return The serialized JSon representation of a given object.
44   - */
45   - public static String toJson(Object object) {
46   - return new GsonBuilder().serializeSpecialFloatingPointValues().create().toJson(object);
47   - }
48   -
49   - /**
50   - * Print the specified object in JSON format in a file on the temporary directory.
51   - *
52   - * @param title The name of the file.
53   - * @param obj the object to print in a file.
54   - * @return The path of the file.
55   - */
56   - public static String writeObject(String title, Object obj) {
57   - Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().setPrettyPrinting()
58   - .create();
59   - String json = gson.toJson(obj);
60   - String path = Consts.TMP_DIR + "/" + title + ".json";
61   - try (FileWriter writer = new FileWriter(path)) {
62   - writer.write(json);
63   -
64   - } catch (IOException e) {
65   - Debug.LOGGER.warning("Can not print in the file " + path + e);
66   - }
67   - Debug.LOGGER.info("A json file representing " + title + " (" + obj.getClass().getName()
68   - + ") has been created on " + path);
69   -
70   - return path;
71   - }
72   -}
src/main/java/eu/omp/irap/vespa/votable/utils/Network.java
... ... @@ -30,8 +30,7 @@ import java.util.Map;
30 30 import java.util.logging.Level;
31 31 import java.util.logging.Logger;
32 32  
33   -import com.google.gson.JsonObject;
34   -import com.google.gson.JsonParser;
  33 +import org.json.JSONObject;
35 34  
36 35 import eu.omp.irap.vespa.votable.Consts;
37 36  
... ... @@ -83,7 +82,7 @@ public class Network {
83 82 * @return The JSon object corresponding to the JSon text returned by the query.
84 83 * @throws CantSendQueryException The query can not be sent.
85 84 */
86   - public static JsonObject readJson(String request) throws CantSendQueryException {
  85 + public static JSONObject readJson(String request) throws CantSendQueryException {
87 86 try (BufferedReader reader = new BufferedReader(
88 87 new InputStreamReader(new URL(request).openStream()))) {
89 88 StringBuilder buffer = new StringBuilder();
... ... @@ -92,7 +91,7 @@ public class Network {
92 91 while ((read = reader.read(chars)) != -1) {
93 92 buffer.append(chars, 0, read);
94 93 }
95   - return new JsonParser().parse(buffer.toString()).getAsJsonObject();
  94 + return new JSONObject(buffer.toString());
96 95 } catch (IOException e) {
97 96 throw new CantSendQueryException("Can not send the Json query " + request, e);
98 97 }
... ...
src/main/java/eu/omp/irap/vespa/votable/votabledata/BinaryStreamParser.java
... ... @@ -28,7 +28,6 @@ import javax.xml.bind.DatatypeConverter;
28 28 import eu.omp.irap.vespa.epntapclient.votable.model.DataType;
29 29 import eu.omp.irap.vespa.epntapclient.votable.model.Field;
30 30 import eu.omp.irap.vespa.epntapclient.votable.model.Stream;
31   -import eu.omp.irap.vespa.votable.utils.Debug;
32 31 import eu.omp.irap.vespa.votable.votable.VOTableException.CantParseVOTableException;
33 32  
34 33 /**
... ... @@ -133,8 +132,6 @@ public final class BinaryStreamParser implements DataParser {
133 132 }
134 133 nValue++;
135 134 }
136   -
137   - Debug.writeObject("voTableData", data);
138 135 return data;
139 136 }
140 137  
... ...