Load in a JSONSerialable stored in a file @param object @param input_path @throws Exception
(T object, String input_path)
| 181 | * @throws Exception |
| 182 | */ |
| 183 | public static <T extends JSONSerializable> void load(T object, String input_path) |
| 184 | throws IOException { |
| 185 | if (LOG.isDebugEnabled()) { |
| 186 | LOG.debug( |
| 187 | "Loading in serialized {} from '{}'", object.getClass().getSimpleName(), input_path); |
| 188 | } |
| 189 | |
| 190 | String contents; |
| 191 | |
| 192 | try (InputStream in = JSONUtil.class.getResourceAsStream(input_path)) { |
| 193 | contents = IOUtils.toString(in, Charset.defaultCharset()); |
| 194 | } |
| 195 | |
| 196 | try { |
| 197 | object.fromJSON(new JSONObject(contents)); |
| 198 | } catch (Exception ex) { |
| 199 | LOG.error( |
| 200 | "Failed to deserialize the {} from file '{}'", |
| 201 | object.getClass().getSimpleName(), |
| 202 | input_path, |
| 203 | ex); |
| 204 | throw new IOException(ex); |
| 205 | } |
| 206 | |
| 207 | if (LOG.isDebugEnabled()) { |
| 208 | LOG.debug("The loading of the {} is complete", object.getClass().getSimpleName()); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * For a given list of Fields, write out the contents of the corresponding field to the JSONObject |