@Override public void toJson(final Writer out, final T object) { try (StringWriter writer = new StringWriter()) { this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object); JsonValue.readHjson(writer.toString()).writeTo(out, Stringify.FORMATTED); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
@Override public void toJson(final File out, final T object) { try (StringWriter writer = new StringWriter()) { this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object); JsonValue.readHjson(writer.toString()).writeTo(new BufferedWriter(new FileWriter(out))); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
private void readAccountsFromJsonResource() { try (Reader reader = new InputStreamReader(jsonResource.getInputStream(), StandardCharsets.UTF_8)) { final TypeReference<Map<String, JsonBackedAccount>> personList = new TypeReference<>() { }; this.jsonBackedAccounts = MAPPER.readValue(JsonValue.readHjson(reader).toString(), personList); } catch (final Exception e) { LOGGER.warn(e.getMessage(), e); } }
@SneakyThrows private void loadResource(final Resource res) { try (Reader reader = new InputStreamReader(res.getInputStream(), StandardCharsets.UTF_8)) { val personList = new TypeReference<Map<String, UserAuthorizationDefinition>>() { }; this.rules = this.objectMapper.readValue(JsonValue.readHjson(reader).toString(), personList); } }
@Override @SneakyThrows public void to(final OutputStream out, final T object) { try (val writer = new StringWriter()) { this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object); val hjsonString = isJsonFormat() ? JsonValue.readHjson(writer.toString()).toString(Stringify.HJSON) : writer.toString(); IOUtils.write(hjsonString, out, StandardCharsets.UTF_8); } }
public static JsonNode parse(File input) throws IOException { try (FileReader fr = new FileReader(input)) { return mapper.readTree(JsonValue.readHjson(fr).toString()); } } }
@Override public void toJson(final OutputStream out, final T object) { try (StringWriter writer = new StringWriter()) { this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object); final String hjsonString = JsonValue.readHjson(writer.toString()).toString(Stringify.HJSON); IOUtils.write(hjsonString, out); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
/** * Read json from stream. * * @param json the json * @return the string * @throws IOException the io exception */ protected String readJsonFrom(final InputStream json) throws IOException { return isJsonFormat() ? JsonValue.readHjson(IOUtils.toString(json, StandardCharsets.UTF_8)).toString() : String.join("\n", IOUtils.readLines(json, StandardCharsets.UTF_8)); }
@SneakyThrows private void readResourceForInterrupts() { this.interrupts = new LinkedHashMap<>(); if (ResourceUtils.doesResourceExist(resource)) { try (Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) { final TypeReference<Map<String, InterruptResponse>> personList = new TypeReference<>() { }; this.interrupts = MAPPER.readValue(JsonValue.readHjson(reader).toString(), personList); } } } }
@SneakyThrows private Set<ConsentDecision> readDecisionsFromJsonResource() { if (ResourceUtils.doesResourceExist(jsonResource)) { try (Reader reader = new InputStreamReader(jsonResource.getInputStream(), StandardCharsets.UTF_8)) { final TypeReference<Set<ConsentDecision>> personList = new TypeReference<>() { }; return MAPPER.readValue(JsonValue.readHjson(reader).toString(), personList); } } return new LinkedHashSet<>(0); }
@SneakyThrows private void readTrustedRecordsFromResource() { this.storage = new LinkedHashMap<>(); if (ResourceUtils.doesResourceExist(location)) { try (Reader reader = new InputStreamReader(location.getInputStream(), StandardCharsets.UTF_8)) { val personList = new TypeReference<Map<String, MultifactorAuthenticationTrustRecord>>() { }; this.storage = MAPPER.readValue(JsonValue.readHjson(reader).toString(), personList); } } }
@Override public T fromJson(final String json) { try { final String jsonString = JsonValue.readHjson(json).toString(); return this.objectMapper.readValue(jsonString, getTypeToSerialize()); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
@Override public T fromJson(final File json) { try { final String jsonString = JsonValue.readHjson(FileUtils.readFileToString(json)).toString(); return this.objectMapper.readValue(jsonString, getTypeToSerialize()); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
@Override public T fromJson(final InputStream json) { try { final String jsonString = JsonValue.readHjson(IOUtils.toString(json)).toString(); return this.objectMapper.readValue(jsonString, getTypeToSerialize()); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
@Override public T fromJson(final Reader json) { try { final String jsonString = JsonValue.readHjson(json).toString(); return this.objectMapper.readValue(jsonString, getTypeToSerialize()); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
@Override public String render(final Map<String, Object> model, final AccessToken accessToken) { val value = getRenderedUserProfile(model); LOGGER.debug("Final user profile is [{}]", JsonValue.readHjson(value).toString(Stringify.FORMATTED)); return value; }
@Override @SneakyThrows public T from(final File json) { val string = isJsonFormat() ? JsonValue.readHjson(FileUtils.readFileToString(json, StandardCharsets.UTF_8)).toString() : FileUtils.readFileToString(json, StandardCharsets.UTF_8); return readObjectFromString(string); }
@Override @SneakyThrows public T from(final Reader json) { val string = isJsonFormat() ? JsonValue.readHjson(json).toString() : String.join("\n", IOUtils.readLines(json)); return readObjectFromString(string); }
@Override @SneakyThrows public T from(final String json) { val jsonString = isJsonFormat() ? JsonValue.readHjson(json).toString() : json; return readObjectFromString(jsonString); }
JsonValue getJson() throws IOException, FilesystemException { if (null == this.json_cache) { final IFile file = this.getFile(); if (file.exists()) { this.json_cache = JsonValue.readHjson(file.reader()); } else { } } return this.json_cache; }