Tabnine Logo
JsonValue
Code IndexAdd Tabnine to your IDE (free)

How to use
JsonValue
in
org.hjson

Best Java code snippets using org.hjson.JsonValue (Showing top 20 results out of 315)

origin: io.macgyver/macgyver-core

public static JsonNode parse(String input) throws IOException {
  return mapper.readTree(JsonValue.readHjson(input).toString());
}
origin: hjson/hjson-java

@Override
public boolean asBoolean() {
 return value==Iv.N ? super.asBoolean() : value==Iv.T;
}
origin: org.hjson/hjson

 public String stringify(JsonValue value)
 {
  if (stringify && value.isNumber() && value.asLong()==value.asDouble())
  {
   return "0x"+Long.toHexString(value.asLong());
  }
  else
  {
   return null;
  }
 }
}
origin: org.hjson/hjson

 public String stringify(JsonValue value)
 {
  if (!value.isNumber()) return null;
  double val=value.asDouble();
  if (val==Double.POSITIVE_INFINITY) return "Inf";
  else if (val==Double.NEGATIVE_INFINITY) return "-Inf";
  else if (Double.isNaN(val)) return "NaN";
  else if (val==0.0 && 1/val==Double.NEGATIVE_INFINITY) return "-0";
  else return null;
 }
}
origin: org.hjson/hjson

public void save(JsonValue value, Writer tw, int level) throws IOException {
 boolean following=false;
 switch (value.getType()) {
  case OBJECT:
   JsonObject obj=value.asObject();
   if (obj.size()>0) nl(tw, level);
   tw.write('{');
    JsonType vType=v.getType();
    if (format && vType!=JsonType.ARRAY && vType!=JsonType.OBJECT) tw.write(" ");
    if (v==null) tw.write("null");
   break;
  case ARRAY:
   JsonArray arr=value.asArray();
   int n=arr.size();
   if (n>0) nl(tw, level);
    if (following) tw.write(",");
    JsonValue v=arr.get(i);
    JsonType vType=v.getType();
    if (vType!=JsonType.ARRAY && vType!=JsonType.OBJECT) nl(tw, level+1);
    save(v, tw, level+1);
   break;
  case BOOLEAN:
   tw.write(value.isTrue()?"true":"false");
   break;
  case STRING:
   tw.write('"');
origin: org.hjson/hjson

/**
 * Returns the JSON string for this value in its minimal form, without any additional whitespace.
 * The result is guaranteed to be a valid input for the method {@link #readJSON(String)} and to
 * create a value that is <em>equal</em> to this object.
 *
 * @return a JSON string that represents this value
 */
@Override
public String toString() {
 return toString(Stringify.PLAIN);
}
origin: net.akehurst.application.framework/net.akehurst.application.framework.technology.persistence.filesystem

Object convertJsonToJava(final JsonValue value) throws PersistentStoreException {
  if (null == value) {
    return null;
  } else if (value.isString()) {
    return value.asString();
  } else if (value.isNumber()) {
    return value.asDouble();
  } else if (value.isBoolean()) {
    return value.asBoolean();
  } else if (value.isArray()) {
    final List<Object> list = new ArrayList<>();
    for (final JsonValue av : value.asArray()) {
      final Object o = this.convertJsonToJava(av);
      list.add(o);
    }
    return list;
  } else if (value.isObject()) {
    final Map<String, Object> map = new HashMap<>();
    for (final String k : value.asObject().names()) {
      final JsonValue jv = value.asObject().get(k);
      final Object v = this.convertJsonToJava(jv);
      map.put(k, v);
    }
    return map;
  } else {
    throw new PersistentStoreException("Unknown JSON type.", null);
  }
}
origin: hjson/hjson-java

private static boolean test(String name, String file, boolean inputCr, boolean outputCr) throws Exception {
 int extIdx=file.lastIndexOf('.');
 boolean isJson=extIdx>=0 && file.substring(extIdx).equals(".json");
 boolean shouldFail=name.startsWith("fail");
 JsonValue.setEol(outputCr?"\r\n":"\n");
 String text=load(file, inputCr);
 try {
  HjsonOptions opt=new HjsonOptions();
  opt.setParseLegacyRoot(false);
  JsonValue data=JsonValue.readHjson(text, opt);
  String data1=data.toString(Stringify.FORMATTED);
  String hjson1=data.toString(Stringify.HJSON);
  if (!shouldFail) {
   JsonValue result=JsonValue.readJSON(load(name+"_result.json", inputCr));
   String data2=result.toString(Stringify.FORMATTED);
   String hjson2=load(name+"_result.hjson", outputCr);
   if (!data1.equals(data2)) return failErr(name, "parse", data1, data2);
   if (!hjson1.equals(hjson2)) return failErr(name, "stringify", hjson1, hjson2);
   if (isJson) {
    String json1=data.toString(), json2=JsonValue.readHjson(text, opt).toString();
    if (!json1.equals(json2)) return failErr(name, "json chk", json1, json2);
   }
  }
  else return failErr(name, "should fail", null, null);
 }
 catch (Exception e) {
  if (!shouldFail) return failErr(name, "exception", e.toString(), "");
 }
 return true;
}
origin: org.jasig.cas/cas-server-core-util

@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);
  }
}
origin: io.macgyver/macgyver-core

public static JsonNode parse(Reader input) throws Exception {
  return mapper.readTree(JsonValue.readJSON(input).toString());
}
origin: Panda-Programming-Language/Panda

@Override
public WildcardCondition create(String condition) {
  boolean renamed = false;
  if (condition.startsWith(NOT_TOKEN)) {
    condition = StringUtils.replaceFirst(condition, NOT_TOKEN, TOKEN);
    renamed = true;
  }
  String[] elements =  StringUtils.splitFirst(condition, " ");
  boolean not = renamed;
  if (elements.length < 2) {
    throw new PandaFrameworkException("Token condition does renamed contain specification");
  }
  String source = elements[1]
      .replace("{", "{" + System.lineSeparator())
      .replace("}", System.lineSeparator() + "}");
  JsonObject conditions = JsonValue
      .readHjson(source)
      .asObject();
  return representation -> check(conditions, representation).negate(not);
}
origin: net.akehurst.application.framework/net.akehurst.application.framework.technology.persistence.filesystem

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;
}
origin: TridentSDK/TridentSDK

/**
 * Parses a click event from the given JSON.
 *
 * @param json The JSON.
 * @return The click event.
 */
public static HoverEvent fromJson(JsonValue json) {
  return new HoverEvent(HoverAction.valueOf(json.asObject().get("action").asString().toUpperCase()), json.asObject().get("value"));
}
origin: org.hjson/hjson

/**
 * Returns the <code>String</code> value of the member with the specified name in this object. If
 * this object does not contain a member with this name, the given default value is returned. If
 * this object contains multiple members with the given name, the last one is picked. If this
 * member's value does not represent a JSON string, an exception is thrown.
 *
 * @param name
 *          the name of the member whose value is to be returned
 * @param defaultValue
 *          the value to be returned if the requested member is missing
 * @return the value of the last member with the specified name, or the given default value if
 *         this object does not contain a member with that name
 */
public String getString(String name, String defaultValue) {
 JsonValue value=get(name);
 return value!=null ? value.asString() : defaultValue;
}
origin: org.hjson/hjson

/**
 * Writes the JSON representation of this value to the given writer in its minimal form, without
 * any additional whitespace.
 * <p>
 * Writing performance can be improved by using a {@link java.io.BufferedWriter BufferedWriter}.
 * </p>
 *
 * @param writer the writer to write this value to
 * @throws IOException if an I/O error occurs in the writer
 */
public void writeTo(Writer writer) throws IOException {
 writeTo(writer, Stringify.PLAIN);
}
origin: hjson/hjson-java

public void save(JsonValue value, Writer tw, int level) throws IOException {
 boolean following=false;
 switch (value.getType()) {
  case OBJECT:
   JsonObject obj=value.asObject();
   if (obj.size()>0) nl(tw, level);
   tw.write('{');
    JsonType vType=v.getType();
    if (format && vType!=JsonType.ARRAY && vType!=JsonType.OBJECT) tw.write(" ");
    if (v==null) tw.write("null");
   break;
  case ARRAY:
   JsonArray arr=value.asArray();
   int n=arr.size();
   if (n>0) nl(tw, level);
    if (following) tw.write(",");
    JsonValue v=arr.get(i);
    JsonType vType=v.getType();
    if (vType!=JsonType.ARRAY && vType!=JsonType.OBJECT) nl(tw, level+1);
    save(v, tw, level+1);
   break;
  case BOOLEAN:
   tw.write(value.isTrue()?"true":"false");
   break;
  case STRING:
   tw.write('"');
origin: hjson/hjson-java

/**
 * Returns the JSON string for this value in its minimal form, without any additional whitespace.
 * The result is guaranteed to be a valid input for the method {@link #readJSON(String)} and to
 * create a value that is <em>equal</em> to this object.
 *
 * @return a JSON string that represents this value
 */
@Override
public String toString() {
 return toString(Stringify.PLAIN);
}
origin: net.akehurst.application.framework/net.akehurst.application.framework.technology.persistence.filesystem

if (null == value) {
  return null;
} else if (value.isString()) {
  final T t = this.af.createDatatype(itemType, value.asString());
  return t;
} else if (value.isNumber()) {
  final T t = this.af.createDatatype(itemType, value.asDouble());
  return t;
} else if (value.isBoolean()) {
  final T t = this.af.createDatatype(itemType, value.asBoolean());
  return t;
} else if (value.isArray()) {
  if (List.class.isAssignableFrom(itemType)) {
    final List list = new ArrayList<>();
    for (final JsonValue av : value.asArray()) {
      final Object o = this.convertJsonToJava(av);
      list.add(o);
    throw new PersistentStoreException("Cannot convert JSON Array to List.", null);
} else if (value.isObject()) {
  if (Map.class.isAssignableFrom(itemType)) {
    final Map<String, Object> map = new HashMap<>();
    for (final String k : value.asObject().names()) {
      final JsonValue jv = value.asObject().get(k);
      final Object v = this.convertJsonToJava(jv);
      map.put(k, v);
origin: org.jasig.cas/cas-server-core-util

@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);
  }
}
origin: io.macgyver/macgyver-core

public static JsonNode parse(InputStream input) throws Exception {
  return mapper.readTree(JsonValue.readJSON(new InputStreamReader(input))
      .toString());
}
org.hjsonJsonValue

Javadoc

Represents a JSON value. This can be a JSON object, an array, a number, a string, or one of the literals true, false, and null.

The literals true, false, and null are represented by the constants #TRUE, #FALSE, and #NULL.

JSON objects and arrays are represented by the subtypes JsonObject and JsonArray. Instances of these types can be created using the public constructors of these classes.

Instances that represent JSON numbers, strings and boolean values can be created using the static factory methods #valueOf(String), #valueOf(long), #valueOf(double), etc.

In order to find out whether an instance of this class is of a certain type, the methods #isObject(), #isArray(), #isString(), #isNumber() etc. can be used.

If the type of a JSON value is known, the methods #asObject(), #asArray(), #asString(), #asInt(), etc. can be used to get this value directly in the appropriate target type.

This class is not supposed to be extended by clients.

Most used methods

  • toString
    Returns the JSON/Hjson string for this value using the given formatting.
  • readHjson
    Reads a Hjson value from the given string.
  • asObject
    Returns this JSON value as JsonObject, assuming that this value represents a JSON object. If this is
  • asString
    Returns this JSON value as String, assuming that this value represents a JSON string. If this is not
  • asArray
    Returns this JSON value as JsonArray, assuming that this value represents a JSON array. If this is n
  • asBoolean
    Returns this JSON value as a boolean value, assuming that this value is either true or false. If thi
  • isNumber
    Detects whether this value represents a JSON number.
  • writeTo
    Writes the JSON/Hjson representation of this value to the given writer using the given formatting. W
  • asDouble
    Returns this JSON value as a double value, assuming that this value represents a JSON number. If thi
  • equals
    Indicates whether some other object is "equal to" this one according to the contract specified in Ob
  • hashCode
  • readJSON
    Reads a JSON value from the given string.
  • hashCode,
  • readJSON,
  • asFloat,
  • asInt,
  • asLong,
  • getType,
  • isBoolean,
  • isObject,
  • isPunctuatorChar,
  • isString

Popular in Java

  • Making http requests using okhttp
  • requestLocationUpdates (LocationManager)
  • getSharedPreferences (Context)
  • getApplicationContext (Context)
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now