Skip to content

Commit

Permalink
removing temporary workaround of "#" JSON pointer handling from JsonP…
Browse files Browse the repository at this point in the history
…ointerEvaluator - it has been fixed in stleary/JSON-java#292
  • Loading branch information
erosb committed May 18, 2017
1 parent d50ba86 commit fed103a
Showing 1 changed file with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package org.everit.json.schema.loader;

import org.everit.json.schema.SchemaException;
import org.json.*;

import java.io.*;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONPointer;
import org.json.JSONPointerException;
import org.json.JSONTokener;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.util.function.Supplier;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -26,8 +35,10 @@ static class QueryResult {
/**
* Constructor.
*
* @param containingDocument the JSON document which contains the query result.
* @param queryResult the JSON object being the result of the query execution.
* @param containingDocument
* the JSON document which contains the query result.
* @param queryResult
* the JSON object being the result of the query execution.
*/
QueryResult(JsonObject containingDocument, JsonObject queryResult) {
this.containingDocument = requireNonNull(containingDocument, "containingDocument cannot be null");
Expand Down Expand Up @@ -118,7 +129,8 @@ static final JsonPointerEvaluator forURL(SchemaClient schemaClient, String url)
* Queries from {@code document} based on this pointer.
*
* @return a DTO containing the query result and the root document containing the query result.
* @throws IllegalArgumentException if the pointer does not start with {@code '#'}.
* @throws IllegalArgumentException
* if the pointer does not start with {@code '#'}.
*/
public QueryResult query() {
JsonObject document = documentProvider.get();
Expand All @@ -138,24 +150,13 @@ public QueryResult query() {
}

private JsonObject queryFrom(JsonObject document) {
JsonObject result; // temporary workaround
if ("#".equals(fragment)) {
result = document;
JSONObject docAsJSONObj = new JSONObject(document.toMap());
JSONObject resultAsJSONObj = (JSONObject) new JSONPointer(fragment).queryFrom(docAsJSONObj);
if (resultAsJSONObj == null) {
throw new JSONPointerException(format("could not query schema document by pointer [%s]", fragment));
} else {
JSONObject docAsJSONObj = new JSONObject(document.toMap());
JSONObject resultAsJSONObj = (JSONObject) new JSONPointer(fragment).queryFrom(docAsJSONObj);
if (resultAsJSONObj == null) {
result = null;
} else {
result = new JsonObject(resultAsJSONObj.toMap());
}
return new JsonObject(resultAsJSONObj.toMap());
}
if (result == null) {
throw new JSONPointerException(
String.format("could not query schema document by pointer [%s]", fragment));
}
return result;
}


}

0 comments on commit fed103a

Please sign in to comment.