List of usage examples for com.google.gson.stream JsonReader setLenient
public final void setLenient(boolean lenient)
From source file:gov.pnnl.goss.gridappsd.testmanager.CompareResults.java
License:Open Source License
public SimulationOutput getOutputProperties(String path) { Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); JsonReader jsonReader; SimulationOutput testScript = null;//from w ww .jav a 2 s . com try { jsonReader = new JsonReader(new FileReader(path)); jsonReader.setLenient(true); testScript = gson.fromJson(new FileReader(path), SimulationOutput.class); jsonReader.close(); } catch (Exception e) { e.printStackTrace(); } return testScript; }
From source file:Implement.DAO.CommonDAOImpl.java
@Override public boolean insertNewLanguage() { String language = "JSON String"; Gson gson = new Gson(); JsonReader reader = new JsonReader(new StringReader(language)); reader.setLenient(true); JsonObject myobject = gson.fromJson(reader, JsonObject.class); int flag = 0; for (Map.Entry<String, JsonElement> entry : myobject.entrySet()) { String name = entry.getValue().getAsJsonObject().get("name").toString(); if (!name.equals( "\"Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic\"")) { String sql = "INSERT INTO Language" + " VALUES (?)"; jdbcTemplate.update(sql, name.replaceAll("\"", "")); }/* w ww . j a v a2s . com*/ } return true; }
From source file:io.bouquet.v4.GsonFactory.java
License:Apache License
/** * Deserialize the given JSON string to Java object. * * @param <T> Type//from w ww. j a va 2 s . com * @param body The JSON string * @param returnType The type to deserialize inot * @return The deserialized Java object */ @SuppressWarnings("unchecked") public <T> T deserialize(String body, Type returnType) throws ApiException { try { if (getClient().isLenientOnJson()) { JsonReader jsonReader = new JsonReader(new StringReader(body)); // see // https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean) jsonReader.setLenient(true); return gson.fromJson(jsonReader, returnType); } else { return gson.fromJson(body, returnType); } } catch (JsonParseException e) { // Fallback processing when failed to parse JSON form response body: // return the response body string directly for the String return // type; // parse response body into date or datetime for the Date return // type. if (returnType.equals(String.class)) return (T) body; else if (returnType.equals(Date.class)) return (T) getClient().parseDateOrDatetime(body); else throw (e); } catch (Exception e) { throw e; } }
From source file:it.smartcommunitylab.JSON.java
License:Apache License
/** * Deserialize the given JSON string to Java object. * * @param <T> Type//from w w w . java 2 s . c o m * @param body The JSON string * @param returnType The type to deserialize into * @return The deserialized Java object */ @SuppressWarnings("unchecked") public <T> T deserialize(String body, Type returnType) { try { if (isLenientOnJson) { JsonReader jsonReader = new JsonReader(new StringReader(body)); // see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean) jsonReader.setLenient(true); return gson.fromJson(jsonReader, returnType); } else { return gson.fromJson(body, returnType); } } catch (JsonParseException e) { // Fallback processing when failed to parse JSON form response body: // return the response body string directly for the String return type; if (returnType.equals(String.class)) return (T) body; else throw (e); } }
From source file:little.nj.mprisdroid.ClientFragment.java
License:Open Source License
/** * Start the listener thread for server responses *//* ww w . j ava2 s.c o m*/ public void startListening() { Log.d(TAG, "ClientFragment: startListening"); m_thread = new Thread(new Runnable() { @Override public void run() { try { JsonReader reader = new JsonReader(new InputStreamReader(m_is)); reader.setLenient(true); do { final ServerResponse resp = m_gson.fromJson(reader, ServerResponse.class); handleResponse(resp); } while (!Thread.interrupted()); } catch (Exception ie) { if (!disconnecting) Log.e(TAG, "ClientFragment: Exception while Listening", ie); signalDisconnect(); } } }); m_thread.start(); }
From source file:logic.MyMQ.java
public void recibir(int ciclos, String DB_server) { String recieve;//from w ww.ja va 2 s.com long currentTimeMillis = System.currentTimeMillis(); for (int i = 0; i < ciclos; i++) { try { recieve = communication.recieve(host, port, "1"); Gson gson = new Gson(); DefaultMensaje def_msg; String ced = ""; //recieve = recieve.replace('\0','0'); System.out.println(" string recibido :" + recieve); JsonReader reader = new JsonReader(new StringReader(recieve)); reader.setLenient(true); def_msg = gson.fromJson(reader, DefaultMensaje.class); ced = def_msg.Cedula; insert(def_msg, DB_server); } catch (IOException ex) { Logger.getLogger(MyMQ.class.getName()).log(Level.SEVERE, null, ex); } } long currentTimeMillisFin = System.currentTimeMillis(); System.out.println(" Tiempo Final: " + (currentTimeMillisFin - currentTimeMillis) + " milisegundos"); }
From source file:melnorme.lang.utils.gson.JsonParserX.java
License:Open Source License
public static JsonReader newReader(Reader reader, boolean lenient) { JsonReader jsonReader = new JsonReader(reader); jsonReader.setLenient(lenient); return jsonReader; }
From source file:melnorme.lang.utils.gson.JsonParserX.java
License:Open Source License
public JsonElement parse(Reader reader, boolean lenient) throws IOException, JsonSyntaxExceptionX { JsonReader json = new JsonReader(reader); boolean originalLenient = json.isLenient(); json.setLenient(lenient); try {//from ww w. ja v a 2 s . c o m return parse(json); } finally { json.setLenient(originalLenient); } }
From source file:net.daporkchop.toobeetooteebot.text.JsonUtils.java
License:Open Source License
public static <T> T gsonDeserialize(Gson gsonIn, Reader readerIn, Class<T> adapter, boolean lenient) { try {/* ww w . j av a 2s.c o m*/ JsonReader jsonreader = new JsonReader(readerIn); jsonreader.setLenient(lenient); return gsonIn.getAdapter(adapter).read(jsonreader); } catch (IOException ioexception) { throw new JsonParseException(ioexception); } }
From source file:net.daporkchop.toobeetooteebot.text.JsonUtils.java
License:Open Source License
public static <T> T fromJson(Gson p_193838_0_, Reader p_193838_1_, Type p_193838_2_, boolean p_193838_3_) { try {//w w w.j a va2 s . c o m JsonReader jsonreader = new JsonReader(p_193838_1_); jsonreader.setLenient(p_193838_3_); return (T) p_193838_0_.getAdapter(TypeToken.get(p_193838_2_)).read(jsonreader); } catch (IOException ioexception) { throw new JsonParseException(ioexception); } }