public boolean loadInfoFromResourceFile() { ObjectMapper objMapper = new ObjectMapper(); // Get the location of the class files at runtime, backtrack a level to the root directory, // Then get the path to the resource directory. try { File inFile = new File(configFileLocation); if (!inFile.exists()) { // The file doesn't exist. Create it with default empty values. writeInfoToResourceFile(); } // JsonNode rootNode = objMapper.readTree(new File("./res/configItems/userConfig.json")); // Get the location of the class files at runtime, backtrack a level to the root directory, // Then get the path to the resource directory. JsonNode rootNode = objMapper.readTree(inFile); loginId = rootNode.path("loginId").getTextValue(); mainSummoner = rootNode.path("mainSummoner").getTextValue(); mainServer = LeagueServer.findServerByCode(rootNode.path("mainServer").getTextValue()); clientVersion = rootNode.path("client version").getTextValue(); Iterator<String> fieldIterator = rootNode.getFieldNames(); while (fieldIterator.hasNext()) { String currentField = fieldIterator.next(); if (!currentField.startsWith("summoner")) { continue; } summonerList.add(rootNode.path(currentField).getTextValue()); } } catch (JsonProcessingException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return true; }
@Override public Response toResponse(JsonProcessingException exception) { /* * If the error is in the JSON generation, it's a server error. */ if (exception instanceof JsonGenerationException) { LOG.warn(exception, "Error generating JSON"); return Response.serverError().build(); } final String message = exception.getMessage(); /* * If we can't deserialize the JSON because someone forgot a no-arg constructor, it's a * server error and we should inform the developer. */ if (message.startsWith("No suitable constructor found")) { LOG.error(exception, "Unable to deserialize the specific type"); return Response.serverError().build(); } /* * Otherwise, it's those pesky users. */ try { LOG.debug(exception, "Unable to process JSON"); final StringWriter writer = new StringWriter(4096); errorHandler.writeErrorPage(request, writer, 400, stripLocation(message), false); return Response.status(Response.Status.BAD_REQUEST) .type(MediaType.TEXT_HTML_TYPE) .entity(writer.toString()) .build(); } catch (IOException e) { LOG.debug(e, "Unable to output error message"); return Response.serverError().build(); } }