use of jakarta.json.JsonValue in project JsonPath by jayway.
the class JakartaJsonProvider method proxyAll.
private JsonStructure proxyAll(JsonStructure jsonStruct) {
if (jsonStruct == null) {
return null;
} else if (jsonStruct instanceof JsonArrayProxy) {
return (JsonArray) jsonStruct;
} else if (jsonStruct instanceof JsonArray) {
List<Object> array = new ArrayList<>();
for (JsonValue v : (JsonArray) jsonStruct) {
if (v instanceof JsonStructure) {
v = proxyAll((JsonStructure) v);
}
array.add(v);
}
return new JsonArrayProxy(jsonBuilderFactory.createArrayBuilder(array).build());
} else if (jsonStruct instanceof JsonObjectProxy) {
return (JsonObject) jsonStruct;
} else if (jsonStruct instanceof JsonObject) {
Map<String, Object> map = new LinkedHashMap<>();
for (Map.Entry<String, JsonValue> e : ((JsonObject) jsonStruct).entrySet()) {
JsonValue v = e.getValue();
if (v instanceof JsonStructure) {
v = proxyAll((JsonStructure) v);
}
map.put(e.getKey(), v);
}
return new JsonObjectProxy(jsonBuilderFactory.createObjectBuilder(map).build());
} else {
throw new IllegalArgumentException();
}
}
use of jakarta.json.JsonValue in project jena by apache.
the class LangJSONLD11 method extractPrefixes.
/**
* JSON-LD does not define prefixes.
* <p>
* The use of "prefix:localname" happens for any definition of "prefix" in the
* {@literal @context} even if intended for a URI e.g a property.
* </p>
* <p>
* We could extract any {"key" : "value"} from the context but we add a pragmatic
* filter to to see if the URI value ends in "#", "/" or ":" (for "urn:" and "did:"
* cases).
* </p>
* <p>
* In addition, {@literal @vocab} becomes prefix "".
* </p>
*/
private static void extractPrefixes(Document document, BiConsumer<String, String> action) {
try {
JsonStructure js = document.getJsonContent().get();
JsonValue jv = js.asJsonObject().get(Keywords.CONTEXT);
extractPrefixes(jv, action);
} catch (Throwable ex) {
Log.warn(LangJSONLD11.class, "Unexpected problem while extracting prefixes: " + ex.getMessage(), ex);
}
}
use of jakarta.json.JsonValue in project dash-licenses by eclipse.
the class ClearlyDefinedContentDataTests method testSingleLicense.
@Test
void testSingleLicense() throws Exception {
InputStream input = this.getClass().getResourceAsStream("/write-1.0.3.json");
JsonReader reader = Json.createReader(new InputStreamReader(input, StandardCharsets.UTF_8));
JsonObject data = ((JsonValue) reader.read()).asJsonObject();
ClearlyDefinedContentData info = new ClearlyDefinedContentData("npm/npmjs/-/write/1.0.3", data);
assertEquals("npm/npmjs/-/write/1.0.3", info.getId().toString());
assertEquals("MIT", info.getLicense());
assertEquals("1.0.3", info.getRevision());
assertArrayEquals(new String[] { "MIT" }, info.discoveredLicenses().toArray(String[]::new));
assertEquals(94, info.getScore());
assertEquals(97, info.getEffectiveScore());
assertEquals("https://clearlydefined.io/definitions/npm/npmjs/-/write/1.0.3", info.getUrl());
assertEquals("https://github.com/jonschlinkert/write/tree/f5397515060bf42f75151fcc3c4722517e4e322a", info.getSourceLocation().getUrl());
assertEquals("https://github.com/jonschlinkert/write/archive/refs/tags/1.0.3.zip", info.getSourceLocation().getDownloadUrl());
assertNull(info.getStatus());
}
use of jakarta.json.JsonValue in project opensearch-java by opensearch-project.
the class JsonDataImpl method getParser.
private JsonParser getParser(JsonpMapper mapper) {
// FIXME: inefficient roundtrip through a string. Should be replaced by an Event buffer structure.
StringWriter sw = new StringWriter();
JsonGenerator generator = mapper.jsonProvider().createGenerator(sw);
if (value instanceof JsonValue) {
generator.write((JsonValue) value);
} else {
mapper.serialize(value, generator);
}
generator.close();
return mapper.jsonProvider().createParser(new StringReader(sw.toString()));
}
use of jakarta.json.JsonValue in project avro-util by linkedin.
the class AvscParser method parseExtraProps.
private LinkedHashMap<String, JsonValueExt> parseExtraProps(JsonObjectExt field, Set<String> toIgnore) {
LinkedHashMap<String, JsonValueExt> results = new LinkedHashMap<>(3);
for (Map.Entry<String, JsonValue> entry : field.entrySet()) {
// doc says there are in the order they are in json
String propName = entry.getKey();
if (toIgnore.contains(propName)) {
continue;
}
JsonValueExt propValue = (JsonValueExt) entry.getValue();
results.put(propName, propValue);
}
return results;
}
Aggregations