Search in sources :

Example 1 with JsonValue

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();
    }
}
Also used : ArrayList(java.util.ArrayList) JsonValue(jakarta.json.JsonValue) JsonObject(jakarta.json.JsonObject) JsonString(jakarta.json.JsonString) LinkedHashMap(java.util.LinkedHashMap) JsonArray(jakarta.json.JsonArray) JsonObject(jakarta.json.JsonObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JsonStructure(jakarta.json.JsonStructure)

Example 2 with JsonValue

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);
    }
}
Also used : JsonValue(jakarta.json.JsonValue) JsonStructure(jakarta.json.JsonStructure)

Example 3 with JsonValue

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());
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JsonValue(jakarta.json.JsonValue) JsonReader(jakarta.json.JsonReader) JsonObject(jakarta.json.JsonObject) ClearlyDefinedContentData(org.eclipse.dash.licenses.clearlydefined.ClearlyDefinedContentData) Test(org.junit.jupiter.api.Test)

Example 4 with JsonValue

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()));
}
Also used : StringWriter(java.io.StringWriter) JsonValue(jakarta.json.JsonValue) StringReader(java.io.StringReader) JsonGenerator(jakarta.json.stream.JsonGenerator)

Example 5 with JsonValue

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;
}
Also used : JsonValue(jakarta.json.JsonValue) JsonValueExt(com.linkedin.avroutil1.parser.jsonpext.JsonValueExt) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

JsonValue (jakarta.json.JsonValue)14 Map (java.util.Map)5 JsonObject (jakarta.json.JsonObject)4 JsonString (jakarta.json.JsonString)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 JsonValueExt (com.linkedin.avroutil1.parser.jsonpext.JsonValueExt)3 JsonStructure (jakarta.json.JsonStructure)3 JsonArray (jakarta.json.JsonArray)2 JsonReader (jakarta.json.JsonReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 ClearlyDefinedContentData (org.eclipse.dash.licenses.clearlydefined.ClearlyDefinedContentData)2 Test (org.junit.jupiter.api.Test)2 AvroUnionSchema (com.linkedin.avroutil1.model.AvroUnionSchema)1 CodeLocation (com.linkedin.avroutil1.model.CodeLocation)1 SchemaOrRef (com.linkedin.avroutil1.model.SchemaOrRef)1 JsonArrayExt (com.linkedin.avroutil1.parser.jsonpext.JsonArrayExt)1 JsonNumberExt (com.linkedin.avroutil1.parser.jsonpext.JsonNumberExt)1 JsonObjectExt (com.linkedin.avroutil1.parser.jsonpext.JsonObjectExt)1