private static List<JsonValue> toList(final com.eclipsesource.json.JsonArray minimalJsonArray) { final List<JsonValue> result = new ArrayList<>(minimalJsonArray.size()); for (final com.eclipsesource.json.JsonValue minimalJsonValue : minimalJsonArray) { result.add(convert(minimalJsonValue)); } return result; }
/** * Reads the entire input stream from the specified reader and parses it as JSON value. The input stream is expected * to contain a valid JSON value with optional whitespace padding. * <p> * As characters are read in chunks and buffered internally it does <em>not</em> improve reading performance to wrap * an existing reader in a {@code BufferedReader}. * </p> * * @param reader the reader to read the JSON value from. * @return a JSON value which represents the read stream. * @throws NullPointerException if {@code reader} is {@code null}. * @throws JsonParseException if an I/O error occurred or if the input is no valid JSON. */ public static JsonValue readFrom(final Reader reader) { requireNonNull(reader, "The reader must not be null!"); final com.eclipsesource.json.JsonValue minimalJsonValue = tryToRead(reader); return convert(minimalJsonValue); }
/** * Reads the given string and creates a JSON value based on the read data. The actual type of this JSON value is * unknown but can be obtained by invoking the {@code is...} methods. * * @param json the JSON document to read. * @return a JSON value representing the read document. This value can be a JSON literal, a JSON object and so on. * @throws NullPointerException if {@code json} is empty. * @throws JsonParseException if {@code json} is empty or if it is no valid JSON. */ public static JsonValue readFrom(final String json) { requireNonNull(json, "The JSON to read from must not be null!"); if (json.isEmpty()) { throw new JsonParseException("The JSON to read from must not be empty!"); } final com.eclipsesource.json.JsonValue minimalJsonValue = tryToRead(json); return convert(minimalJsonValue); }
/** * Tries to guess the associated JsonValue for the specified object. * * @param value the value to be converted. * @param <T> the type of {@code value}. * @return a JsonValue representation of {@code value}. * @throws JsonParseException if {@code value} is not defined for JSON. */ static <T> JsonValue getAppropriateValue(@Nullable final T value) { final JsonValue result; if (null == value) { result = nullLiteral(); } else if (value instanceof JsonValue) { result = ((JsonValue) value); } else if (value instanceof String || value instanceof CharSequence) { result = newValue(String.valueOf(value)); } else { result = convert(tryToRead(String.valueOf(value))); } return result; }
private static Map<String, JsonField> toMap(final com.eclipsesource.json.JsonObject minimalJsonObject) { final Map<String, JsonField> result = new LinkedHashMap<>(minimalJsonObject.size()); for (final com.eclipsesource.json.JsonObject.Member member : minimalJsonObject) { final JsonKey key = newKey(member.getName()); final JsonValue value = convert(member.getValue()); result.put(key.toString(), newField(key, value)); } return result; }
@Override protected String createStringRepresentation() { final com.eclipsesource.json.JsonObject minJsonObject = new com.eclipsesource.json.JsonObject(); fields.values().forEach(field -> minJsonObject.add(field.getKeyName(), JsonFactory.convert(field.getValue()))); return minJsonObject.toString(); }
@Override protected String createStringRepresentation() { final com.eclipsesource.json.JsonArray minimalJsonArray = new com.eclipsesource.json.JsonArray(); for (final JsonValue value : values) { minimalJsonArray.add(JsonFactory.convert(value)); } return minimalJsonArray.toString(); }