Java Code Examples for javax.json.JsonReader#read()

The following examples show how to use javax.json.JsonReader#read() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultAnalyzer.java    From aceql-http with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
    * Says if status is OK
    *
    * @return true if status is OK
    */
   public boolean isStatusOk() {

if (jsonResult == null || jsonResult.isEmpty()) {
    return false;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status != null && status.getString().equals("OK")) {
	return true;
    } else {
	return false;
    }
} catch (Exception e) {
    this.parseException = e;
    invalidJsonStream = true;
    return false;
}

   }
 
Example 2
Source File: ResultAnalyzer.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * Returns the value for a name
    *
    * @param name
    * @return the value
    */
   public String getValue(String name) {
if (name == null) {
    throw new NullPointerException("name is null!");
}

if (isInvalidJsonStream()) {
    return null;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString value = (JsonString) object.get(name);

    if (value == null) {
	return null;
    }

    return value.getString();
} catch (Exception e) {
    this.parseException = e;
    return null;
}
   }
 
Example 3
Source File: ResultAnalyzer.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * Returns the int value for a name
    *
    * @param name
    * @return the value
    */
   public int getIntvalue(String name) {
if (name == null) {
    throw new NullPointerException("name is null!");
}

if (isInvalidJsonStream()) {
    return -1;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonNumber value = (JsonNumber) object.get(name);

    if (value == null) {
	return -1;
    }

    return value.intValue();
} catch (Exception e) {
    this.parseException = e;
    return -1;
}
   }
 
Example 4
Source File: ResultAnalyzer.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * Returns the error_type in case of failure
    *
    * @return the error_type in case of failure, -1 if no error
    */
   public int getErrorType() {

if (isInvalidJsonStream()) {
    return 0;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status == null) {
	return -1;
    }

    JsonNumber errorType = (JsonNumber) object.get("error_type");

    if (errorType == null) {
	return -1;
    } else {
	return errorType.intValue();
    }
} catch (Exception e) {
    this.parseException = e;
    return -1;
}

   }
 
Example 5
Source File: ResultAnalyzer.java    From aceql-http with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * Returns the stack_trace in case of failure
    *
    * @return the stack_trace in case of failure, null if no stack_trace
    */
   public String getStackTrace() {

if (isInvalidJsonStream()) {
    return null;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status == null) {
	return null;
    }

    JsonString stackTrace = (JsonString) object.get("stack_trace");
    if (stackTrace == null) {
	return null;
    } else {
	return stackTrace.getString();
    }
} catch (Exception e) {
    this.parseException = e;
    return null;
}

   }
 
Example 6
Source File: JsonProvider.java    From rapid with MIT License 5 votes vote down vote up
@Override
public Object readFrom(Class type, Type genericType, Annotation[] annotations,
                       MediaType mediaType, MultivaluedMap httpHeaders,
                       InputStream entityStream) throws IOException, WebApplicationException {
    // from HTML to methods having @Consumes
    JsonReader jsonReader = Json.createReader(entityStream);
    JsonStructure object = jsonReader.read();
    jsonReader.close();
    entityStream.close();
    return object;
}
 
Example 7
Source File: JsonTestUtils.java    From structlog4j with MIT License 5 votes vote down vote up
/**
 * Ensures message is valid JSON
 */
public void assertJsonMessage(List<LogEntry> entries, int entryIndex) {
    try {
        JsonReader reader = Json.createReader(new StringReader(entries.get(entryIndex).getMessage()));
        JsonStructure parsed = reader.read();
    } catch (Exception e) {
        throw new RuntimeException("Unable to parse: " + entries.get(entryIndex).getMessage(),e);
    }
}
 
Example 8
Source File: JsonUtil.java    From geoportal-server-harvester with Apache License 2.0 4 votes vote down vote up
/**
 * Parse a JSON string.
 * @param json the string
 * @return the structure (JsonAoject or JsonArray)
 */
public static JsonStructure toJsonStructure(String json) {
  JsonReader reader = Json.createReader(new StringReader(json));
  JsonStructure structure = reader.read(); 
  return structure;
}
 
Example 9
Source File: JsonPointerCrud.java    From tutorials with MIT License 3 votes vote down vote up
public JsonPointerCrud(InputStream stream) {

        JsonReader reader = Json.createReader(stream);
        jsonStructure = reader.read();
        reader.close();

    }