List of usage examples for com.google.gson.stream JsonReader isLenient
public final boolean isLenient()
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);//from ww w. j a va 2 s . co m try { return parse(json); } finally { json.setLenient(originalLenient); } }
From source file:org.apache.axis2.json.gson.rpc.JsonUtils.java
License:Apache License
public static Object invokeServiceClass(JsonReader jsonReader, Object service, Method operation, Class[] paramClasses, int paramCount) throws InvocationTargetException, IllegalAccessException, IOException { Object[] methodParam = new Object[paramCount]; Gson gson = new Gson(); String[] argNames = new String[paramCount]; if (!jsonReader.isLenient()) { jsonReader.setLenient(true);/*from w w w .j a v a 2s .co m*/ } jsonReader.beginObject(); jsonReader.nextName(); // get message name from input json stream jsonReader.beginArray(); int i = 0; for (Class paramType : paramClasses) { jsonReader.beginObject(); argNames[i] = jsonReader.nextName(); methodParam[i] = gson.fromJson(jsonReader, paramType); // gson handle all types well and return an object from it jsonReader.endObject(); i++; } jsonReader.endArray(); jsonReader.endObject(); return operation.invoke(service, methodParam); }
From source file:org.onos.yangtools.yang.data.codec.gson.JsonParserStream.java
License:Open Source License
public JsonParserStream parse(final JsonReader reader) throws JsonIOException, JsonSyntaxException { // code copied from gson's JsonParser and Stream classes final boolean lenient = reader.isLenient(); reader.setLenient(true);/*from www .j a va2 s . co m*/ boolean isEmpty = true; try { reader.peek(); isEmpty = false; final CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema( parentNode); read(reader, compositeNodeDataWithSchema); compositeNodeDataWithSchema.write(writer); return this; // return read(reader); } catch (final EOFException e) { if (isEmpty) { return this; // return JsonNull.INSTANCE; } // The stream ended prematurely so it is likely a syntax error. throw new JsonSyntaxException(e); } catch (final MalformedJsonException e) { throw new JsonSyntaxException(e); } catch (final IOException e) { throw new JsonIOException(e); } catch (final NumberFormatException e) { throw new JsonSyntaxException(e); } catch (StackOverflowError | OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e); } finally { reader.setLenient(lenient); } }
From source file:org.opendaylight.controller.sal.rest.gson.JsonParser.java
License:Open Source License
public JsonElement parse(JsonReader reader) throws JsonIOException, JsonSyntaxException { // code copied from gson's JsonParser and Stream classes boolean lenient = reader.isLenient(); reader.setLenient(true);//from w ww.j ava 2 s. c o m boolean isEmpty = true; try { reader.peek(); isEmpty = false; return read(reader); } catch (EOFException e) { if (isEmpty) { return JsonNull.INSTANCE; } // The stream ended prematurely so it is likely a syntax error. throw new JsonSyntaxException(e); } catch (MalformedJsonException e) { throw new JsonSyntaxException(e); } catch (IOException e) { throw new JsonIOException(e); } catch (NumberFormatException e) { throw new JsonSyntaxException(e); } catch (StackOverflowError | OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e); } finally { reader.setLenient(lenient); } }
From source file:org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream.java
License:Open Source License
public JsonParserStream parse(final JsonReader reader) { // code copied from gson's JsonParser and Stream classes final boolean lenient = reader.isLenient(); reader.setLenient(true);/*from w w w .jav a 2 s. c o m*/ boolean isEmpty = true; try { reader.peek(); isEmpty = false; final CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema( parentNode); read(reader, compositeNodeDataWithSchema); compositeNodeDataWithSchema.write(writer); return this; } catch (final EOFException e) { if (isEmpty) { return this; } // The stream ended prematurely so it is likely a syntax error. throw new JsonSyntaxException(e); } catch (final MalformedJsonException | NumberFormatException e) { throw new JsonSyntaxException(e); } catch (final IOException e) { throw new JsonIOException(e); } catch (StackOverflowError | OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e); } finally { reader.setLenient(lenient); } }
From source file:tv.loilo.promise.http.ResponseJsonConverter.java
License:Apache License
@NonNull public static JsonElement parse(@NonNull final JsonReader json) throws JsonIOException, JsonSyntaxException { boolean lenient = json.isLenient(); json.setLenient(true);//from w w w. j av a 2s . co m try { return Streams.parse(json); } catch (StackOverflowError | OutOfMemoryError e) { throw new JsonIOException("Failed parsing JSON source: " + json + " to Json", e); } finally { json.setLenient(lenient); } }