Java 类com.google.gson.stream.MalformedJsonException 实例源码

项目:Capstone2016    文件:ConfigFileTests.java   
/**
 * Test that any mapped dataset files are parsable JSON strings.
 * @throws IOException if the dataset mappings, or any datasets are unaccessible
 * @throws MalformedJsonException if a dataset cannot be parsed into JSON
 */
@Test
public void MappedDatasetsAreJSON() throws IOException, MalformedJsonException {
    Properties prop = new Properties();
    try (InputStream input = new FileInputStream(DATASETS_PATH)) {
        prop.load(input);
    }
    for(Entry<Object, Object> e : prop.entrySet()) {
        File f = new File((SERVLET_CONTEXT_PATH + "/web" + e.getValue().toString().replace("/", SEP)));
        assertTrue(f.exists());

        // Get the dataset json string from file
        final String datasetPath = f.toString();
        byte[] encoded = Files.readAllBytes(Paths.get(datasetPath));
        final String datasetJSON = new String(encoded, StandardCharsets.UTF_8);

        // An exception will be thrown here if the dataset cannot be parsed as JSON.
        JsonObject jObject = new JsonParser().parse(datasetJSON).getAsJsonObject();
    }
    // All mapped datasets have been resolved by the JSON parser.
    assertTrue(true);
}
项目:MiBandDecompiled    文件:Gson.java   
private static void a(Object obj, JsonReader jsonreader)
{
    if (obj != null)
    {
        try
        {
            if (jsonreader.peek() != JsonToken.END_DOCUMENT)
            {
                throw new JsonIOException("JSON document was not fully consumed.");
            }
        }
        catch (MalformedJsonException malformedjsonexception)
        {
            throw new JsonSyntaxException(malformedjsonexception);
        }
        catch (IOException ioexception)
        {
            throw new JsonIOException(ioexception);
        }
    }
}
项目:MiBandDecompiled    文件:JsonParser.java   
public JsonElement parse(Reader reader)
{
    JsonElement jsonelement;
    try
    {
        JsonReader jsonreader = new JsonReader(reader);
        jsonelement = parse(jsonreader);
        if (!jsonelement.isJsonNull() && jsonreader.peek() != JsonToken.END_DOCUMENT)
        {
            throw new JsonSyntaxException("Did not consume the entire document.");
        }
    }
    catch (MalformedJsonException malformedjsonexception)
    {
        throw new JsonSyntaxException(malformedjsonexception);
    }
    catch (IOException ioexception)
    {
        throw new JsonIOException(ioexception);
    }
    catch (NumberFormatException numberformatexception)
    {
        throw new JsonSyntaxException(numberformatexception);
    }
    return jsonelement;
}
项目:FXMaps    文件:MapStore.java   
/**
 * Called to load the serialized {@link Routes} into this store.
 * 
 * @return  a {@code RouteStore} containing previously serialized {@link Route}s
 * or an empty store if there were no Routes previously persisted.
 * 
 * @param path  the path to the persistent store json file
 */
public static MapStore load(String path) {
    path = path == null ? DEFAULT_STORE_PATH : path;

    try {
        Gson gson = new Gson();
        MapStore mapStore = gson.fromJson(
            Files.newBufferedReader(FileSystems.getDefault().getPath(path)), MapStore.class);

        for(String mapName : mapStore.getMaps().keySet()) {
            mapStore.selectMap(mapName);
            mapStore.postDeserialize();
        }

        mapStore.storePath = path;

        return mapStore;
    }catch(MalformedJsonException m) {
        System.out.println(m.getMessage());
        File f = new File(path);
        f.delete();
    }catch(Exception e) {
        System.out.println("No map store found, creating new map store.");
    }
    return new MapStore();
}
项目:GitHub    文件:ExceptionEngine.java   
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof HttpException) {             //HTTP错误
        HttpException httpExc = (HttpException) e;
        ex = new ApiException(e, httpExc.code());
        ex.setMsg("网络错误");  //均视为网络错误
        return ex;
    } else if (e instanceof ServerException) {    //服务器返回的错误
        ServerException serverExc = (ServerException) e;
        ex = new ApiException(serverExc, serverExc.getCode());
        ex.setMsg(serverExc.getMsg());
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException || e instanceof MalformedJsonException) {  //解析数据错误
        ex = new ApiException(e, ANALYTIC_SERVER_DATA_ERROR);
        ex.setMsg("解析错误");
        return ex;
    } else if (e instanceof ConnectException) {//连接网络错误
        ex = new ApiException(e, CONNECT_ERROR);
        ex.setMsg("连接失败");
        return ex;
    } else if (e instanceof SocketTimeoutException) {//网络超时
        ex = new ApiException(e, TIME_OUT_ERROR);
        ex.setMsg("网络超时");
        return ex;
    } else {  //未知错误
        ex = new ApiException(e, UN_KNOWN_ERROR);
        ex.setMsg("未知错误");
        return ex;
    }
}
项目:HutHelper    文件:ExceptionEngine.java   
public static APIException handleException(Throwable throwable){
    throwable.printStackTrace();

    APIException apiException;
    if (throwable instanceof HttpException){
        HttpException httpException = (HttpException) throwable;
        apiException = new APIException(throwable, httpException.code());
        apiException.setMsg("网络错误");
        return apiException;
    }else if (throwable instanceof JsonParseException
            || throwable instanceof JSONException
            || throwable instanceof ParseException
            || throwable instanceof MalformedJsonException){
        apiException = new APIException(throwable, PARSE_SERVER_DATA_ERROR);
        apiException.setMsg("解析数据错误");
        return apiException;
    }else if (throwable instanceof ConnectException){
        apiException = new APIException(throwable, CONNECT_ERROR);
        apiException.setMsg("网络连接失败");
        return apiException;
    }else if (throwable instanceof SocketTimeoutException){
        apiException = new APIException(throwable, CONNECT_TIME_OUT_ERROR);
        apiException.setMsg("网络连接超时");
        return apiException;
    }else if (throwable instanceof ServerException){
        ServerException serverException = (ServerException) throwable;
        apiException = new APIException(serverException, serverException.getCode());
        apiException.setMsg(serverException.getMsg());
        return apiException;
    } else {
        apiException = new APIException(throwable, UN_KNOWN_ERROR);
        apiException.setMsg("未知错误");
        return apiException;
    }
}
项目:SerenityCE    文件:AbstractJsonDataHandler.java   
@Override
public void load() throws IOException {
    if (file.exists()) {
        try {
            loadObject(gson.fromJson(FileUtils.readFileToString(file), targetClass));
        } catch (MalformedJsonException e) {
            e.printStackTrace();
        }
    }
}
项目:speedr    文件:ErrorReporter.java   
private static void sendOtherError(Throwable error, boolean here) {
    if (error instanceof SocketTimeoutException) {
        if (here) Crashlytics.logException(new Exception(HERE + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
        else Crashlytics.logException(new Exception(OVERPASS + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
    } else if (error instanceof java.net.SocketException) {
        if (here) Crashlytics.logException(new Exception(HERE + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
        else Crashlytics.logException(new Exception(OVERPASS + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
    } else if (error instanceof MalformedJsonException) {
        if (here) Crashlytics.logException(new Exception(HERE + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
        else Crashlytics.logException(new Exception(OVERPASS + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
    } else if (error instanceof UnknownHostException) {
        if (here) Crashlytics.logException(new Exception(HERE + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
        else Crashlytics.logException(new Exception(OVERPASS + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
    } else if (error instanceof ProtocolException) {
        if (here) Crashlytics.logException(new Exception(HERE + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
        else Crashlytics.logException(new Exception(OVERPASS + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
    } else if (error instanceof IllegalStateException) {
        if (here) Crashlytics.logException(new Exception(HERE + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
        else Crashlytics.logException(new Exception(OVERPASS + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
    } else if (error instanceof java.io.IOException) {
        if (here) Crashlytics.logException(new Exception(HERE + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
        else Crashlytics.logException(new Exception(OVERPASS + error.toString() + "\n\n" + Arrays.toString(error.getStackTrace()).replaceAll(", ", "\n")));
    } else { //some other exception
        if (here) Crashlytics.logException(new Exception(HERE, error));
        else Crashlytics.logException(new Exception(OVERPASS, error));
    }
}
项目:Palm300Heroes    文件:ExceptionEngine.java   
public static APIException handleException(Throwable throwable){
    throwable.printStackTrace();

    APIException apiException;
    if (throwable instanceof HttpException){
        HttpException httpException = (HttpException) throwable;
        apiException = new APIException(throwable, httpException.code());
        apiException.setMsg("网络错误");
        return apiException;
    }else if (throwable instanceof JsonParseException
            || throwable instanceof JSONException
            || throwable instanceof ParseException
            || throwable instanceof MalformedJsonException){
        apiException = new APIException(throwable, PARSE_SERVER_DATA_ERROR);
        apiException.setMsg("解析数据错误");
        return apiException;
    }else if (throwable instanceof ConnectException){
        apiException = new APIException(throwable, CONNECT_ERROR);
        apiException.setMsg("网络连接失败");
        return apiException;
    }else if (throwable instanceof SocketTimeoutException){
        apiException = new APIException(throwable, CONNECT_TIME_OUT_ERROR);
        apiException.setMsg("网络连接超时");
        return apiException;
    }else if (throwable instanceof ServerException){
        ServerException serverException = (ServerException) throwable;
        apiException = new APIException(serverException, serverException.getCode());
        apiException.setMsg(serverException.getMsg());
        return apiException;
    } else {
        apiException = new APIException(throwable, UN_KNOWN_ERROR);
        apiException.setMsg("未知错误");
        return apiException;
    }
}
项目:intellij-ce-playground    文件:RestService.java   
@Override
public final boolean process(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
  try {
    if (activateToolBeforeExecution()) {
      IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
      if (frame instanceof Window) {
        ((Window)frame).toFront();
      }
    }

    String error = execute(urlDecoder, request, context);
    if (error != null) {
      Responses.sendStatus(HttpResponseStatus.BAD_REQUEST, context.channel(), error, request);
    }
  }
  catch (Throwable e) {
    HttpResponseStatus status;
    // JsonReader exception
    //noinspection InstanceofCatchParameter
    if (e instanceof MalformedJsonException || (e instanceof IllegalStateException && e.getMessage().startsWith("Expected a "))) {
      LOG.warn(e);
      status = HttpResponseStatus.BAD_REQUEST;
    }
    else {
      LOG.error(e);
      status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
    }
    Responses.sendStatus(status, context.channel(), ExceptionUtil.getThrowableText(e), request);
  }
  return true;
}
项目:FMTech    文件:Gson.java   
public final <T> T fromJson(String paramString, Class<T> paramClass)
  throws JsonSyntaxException
{
  Object localObject;
  if (paramString == null) {
    localObject = null;
  }
  for (;;)
  {
    return Primitives.wrap(paramClass).cast(localObject);
    JsonReader localJsonReader = new JsonReader(new StringReader(paramString));
    localObject = fromJson(localJsonReader, paramClass);
    if (localObject == null) {
      continue;
    }
    try
    {
      if (localJsonReader.peek() == JsonToken.END_DOCUMENT) {
        continue;
      }
      throw new JsonIOException("JSON document was not fully consumed.");
    }
    catch (MalformedJsonException localMalformedJsonException)
    {
      throw new JsonSyntaxException(localMalformedJsonException);
    }
    catch (IOException localIOException)
    {
      throw new JsonIOException(localIOException);
    }
  }
}
项目:FMTech    文件:Streams.java   
public static JsonElement parse(JsonReader paramJsonReader)
  throws JsonParseException
{
  int i = 1;
  try
  {
    paramJsonReader.peek();
    i = 0;
    JsonElement localJsonElement = (JsonElement)TypeAdapters.JSON_ELEMENT.read(paramJsonReader);
    return localJsonElement;
  }
  catch (EOFException localEOFException)
  {
    if (i != 0) {
      return JsonNull.INSTANCE;
    }
    throw new JsonIOException(localEOFException);
  }
  catch (MalformedJsonException localMalformedJsonException)
  {
    throw new JsonSyntaxException(localMalformedJsonException);
  }
  catch (IOException localIOException)
  {
    throw new JsonIOException(localIOException);
  }
  catch (NumberFormatException localNumberFormatException)
  {
    throw new JsonSyntaxException(localNumberFormatException);
  }
}
项目:jpapi    文件:Api.java   
/**
 * F�hrt eine Anfrage an die Pewn-API aus und liefert die Antwort.
 * 
 * @param <T>
 *            Der Typ der Antwort.
 * @param call
 *            Die Anfrage.
 * @return Die Antwort der Pewn-API.
 * @throws IOException
 *             wenn ein Fehler bei der Kommunikation mit Pewn auftritt.
 */
public static <T> T executeCall(Call<T> call) throws IOException {
    try {
        retrofit2.Response<T> response = call.execute();
        return response.body();
    } catch (IOException e) {
        if (e instanceof MalformedJsonException)
            throw new JpapiInternalException(e);
        else
            throw e;
    }
}
项目:MiBandDecompiled    文件:Streams.java   
public static JsonElement parse(JsonReader jsonreader)
{
    boolean flag = true;
    JsonElement jsonelement;
    try
    {
        jsonreader.peek();
    }
    catch (EOFException eofexception)
    {
        if (flag)
        {
            return JsonNull.INSTANCE;
        } else
        {
            throw new JsonSyntaxException(eofexception);
        }
    }
    catch (MalformedJsonException malformedjsonexception)
    {
        throw new JsonSyntaxException(malformedjsonexception);
    }
    catch (IOException ioexception)
    {
        throw new JsonIOException(ioexception);
    }
    catch (NumberFormatException numberformatexception)
    {
        throw new JsonSyntaxException(numberformatexception);
    }
    flag = false;
    jsonelement = (JsonElement)TypeAdapters.JSON_ELEMENT.read(jsonreader);
    return jsonelement;
}
项目:FXMaps    文件:Route.java   
/**
 * Called following deserialization to load the observable list. The observable
 * list cannot be serialized using the current method, so we use a simple list
 * for serialization and then copy the data over, after deserialization.
 */
public void postDeserialize() throws MalformedJsonException {
    observableDelegate = FXCollections.observableArrayList(delegate);
    delegate.clear();

    try {
        createUnderlying();
    }catch(NullPointerException npe) {
        throw new MalformedJsonException(npe.getMessage());
    }
}
项目:protostream    文件:ProtobufUtil.java   
public static byte[] fromCanonicalJSON(ImmutableSerializationContext ctx, Reader reader) throws IOException {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   RawProtoStreamWriter writer = RawProtoStreamWriterImpl.newInstance(baos);

   JsonReader jsonReader = new JsonReader(reader);
   jsonReader.setLenient(false);

   try {
      JsonToken token = jsonReader.peek();
      while (jsonReader.hasNext() && !token.equals(END_DOCUMENT)) {
         token = jsonReader.peek();
         switch (token) {
            case BEGIN_OBJECT:
               processJsonDocument(ctx, jsonReader, writer);
               break;
            case NULL:
               jsonReader.nextNull();
               break;
            case END_DOCUMENT:
               break;
            default:
               throw new IllegalStateException("Invalid top level object! Found token: " + token);
         }
      }
      writer.flush();
      return baos.toByteArray();
   } catch (MalformedJsonException e) {
      throw new IllegalStateException("Invalid JSON", e);
   } finally {
      baos.close();
      reader.close();
   }
}
项目:apps-android-wikipedia    文件:CreateAccountInfoClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("┏━┓ ︵  /(^.^/)");

    CreateAccountInfoClient.Callback cb = mock(CreateAccountInfoClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:CreateAccountClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("┏━┓ ︵  /(^.^/)");

    CreateAccountClient.Callback cb = mock(CreateAccountClient.Callback.class);
    Call<CreateAccountResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:EditClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("(-(-_(-_-)_-)-)");

    EditClient.Callback cb = mock(EditClient.Callback.class);
    Call<Edit> call = request(cb, false);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:WikitextClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("(-(-_(-_-)_-)-)");

    WikitextClient.Callback cb = mock(WikitextClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:EditPreviewClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("(-(-_(-_-)_-)-)");

    EditPreviewClient.Callback cb = mock(EditPreviewClient.Callback.class);
    Call<EditPreview> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:ImageLicenseFetchClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    ImageLicenseFetchClient.Callback cb = mock(ImageLicenseFetchClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:GalleryItemClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    GalleryItemClient.Callback cb = mock(GalleryItemClient.Callback.class);
    Call<MwQueryResponse> call = request(cb, false);
    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:DescriptionClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    DescriptionClient.Callback cb = mock(DescriptionClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:NearbyClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("(✿ ♥‿♥)");

    NearbyClient.Callback cb = mock(NearbyClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:UserIdClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("┏━┓ ︵  /(^.^/)");

    UserIdClient.Callback cb = mock(UserIdClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:UserExtendedInfoClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("┏━┓ ︵  /(^.^/)");

    UserExtendedInfoClient.Callback cb = mock(UserExtendedInfoClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:PrefixSearchClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    PrefixSearchClient.Callback cb = mock(PrefixSearchClient.Callback.class);
    Call<PrefixSearchResponse> call = request("foo", cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:FullTextSearchClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    FullTextSearchClient.Callback cb = mock(FullTextSearchClient.Callback.class);
    Call<MwQueryResponse> call = request(null, cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:ReadingListPageInfoClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    ReadingListPageInfoClient.Callback cb = mock(ReadingListPageInfoClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:CaptchaClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    Callback cb = mock(Callback.class);
    Call<Captcha> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:CsrfTokenClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    Callback cb = mock(Callback.class);
    request(cb);

    server().takeRequest();
    assertCallbackFailure(cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:LangLinksClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("⨌⨀_⨀⨌");

    LangLinksClient.Callback cb = mock(LangLinksClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:DescriptionEditClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    Callback cb = mock(Callback.class);
    Call<DescriptionEdit> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:apps-android-wikipedia    文件:PageImagesClientTest.java   
@Test public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");

    PageImagesClient.Callback cb = mock(PageImagesClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);

    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
项目:Capstone2016    文件:ConfigFileTests.java   
/**
 * Test that any mapped dataset files have parsable parameter types.
 * @throws IOException if the dataset mappings, or any datasets are unaccessible
 * @throws MalformedJsonException if a dataset cannot be parsed into JSON
 * @throws java.sql.SQLException
 * @throws java.text.ParseException
 * @throws java.lang.TypeNotPresentException
 */
@Test
public void MappedDatasetsHaveValidParams() throws TypeNotPresentException, IOException, MalformedJsonException, SQLException, ParseException {

    // Unfortunately we need a db connection to test this (not actually queried, but necessary)
    String dbConfigPathTest = DBCONFIG_PATH + ".dev".replace("/", SEP);

    DataSource dsTest = Common.getNestDS(dbConfigPathTest);
    try (
        Connection conn = dsTest.getConnection();
    ) {

        Properties prop = new Properties();
        try (InputStream input = new FileInputStream(DATASETS_PATH)) {
            prop.load(input);
        }
        for(Entry<Object, Object> e : prop.entrySet()) {
            File f = new File((SERVLET_CONTEXT_PATH + "/web" + e.getValue().toString().replace("/", SEP)));
            assertTrue(f.exists());

            // Get the dataset json string from file
            final String datasetPath = f.toString();
            byte[] encoded = Files.readAllBytes(Paths.get(datasetPath));
            final String datasetJSON = new String(encoded, StandardCharsets.UTF_8);

            // Decode from JSON clean enclosing quotes and newlines then return
            JsonObject jObject = new JsonParser().parse(datasetJSON).getAsJsonObject();
            Set<Map.Entry<String, JsonElement>> entries = jObject.entrySet();//will return members of your object
            for (Map.Entry<String, JsonElement> entry: entries) {
                String datasetSQL = entry.getValue().getAsString();

                // Remove the returned quotes as the SQL is a string, but only if its not null-length already.
                datasetSQL = (datasetSQL.length() > 2) ? datasetSQL.substring(1, datasetSQL.length()-1) : "";
                datasetSQL = datasetSQL.replace("\\r\\n", "\n").replace("\\n", "\n");

                // Parse the dataset parameters out of the dataset
                Map<String, String> datasetParams = new HashMap<>();
                List<String> datasetParamOrder = new ArrayList<>();
                Common.parseDatasetParameters(datasetSQL, datasetParams, datasetParamOrder);

                final String cleanSQL = datasetSQL.replaceAll(Common.DATASETPARAM_REGEX, "?");
                System.out.println(cleanSQL);

                // An exception will be thrown here if dataset parameters exists with unsupported types
                try (PreparedStatement st = conn.prepareStatement(cleanSQL);) {
                    Common.bindDynamicParameters(st, datasetParams, datasetParamOrder);
                }
            }
        }
        // All mapped datasets have been resolved by the JSON parser.
        assertTrue(true);
    }
    Common.closeNestDS();
}
项目:demo-app-android-v2-2.3.9    文件:JsonObjectParser.java   
public abstract T jsonParse(JsonReader reader) throws MalformedJsonException, JSONException, IOException,
ParseException, InternalException;
项目:FXMaps    文件:MapStore.java   
/**
 * Called following deserialization to load the observable list. The observable
 * list cannot be serialized using the current method, so we use a simple list
 * for serialization and then copy the data over, after deserialization.
 */
public void postDeserialize() throws MalformedJsonException {
    for(Route r : maps.get(selectedMap).getRoutes()) {
        r.postDeserialize();
    }
}
项目:demo-app-android    文件:GsonParser.java   
@Override
public T jsonParse(JsonReader reader) throws MalformedJsonException, JSONException, IOException, ParseException, InternalException {
    return gson.fromJson(reader,this.type);
}
项目:demo-app-android    文件:GsonArrayParser.java   
@Override
public ArrayList<T> jsonParse(JsonReader reader) throws MalformedJsonException, JSONException, IOException, ParseException, InternalException {
    return gson.fromJson(reader,type.getType());
}