Search in sources :

Example 1 with JsonReaderFactory

use of jakarta.json.JsonReaderFactory in project resteasy by resteasy.

the class AbstractJsonpProvider method findReader.

protected JsonReader findReader(MediaType mediaType, InputStream is) {
    ContextResolver<JsonReaderFactory> resolver = providers.getContextResolver(JsonReaderFactory.class, mediaType);
    JsonReaderFactory factory = null;
    if (resolver != null) {
        factory = resolver.getContext(JsonReaderFactory.class);
    }
    if (factory == null) {
        factory = readerFactory;
    }
    Charset charset = getCharset(mediaType);
    return charset == null ? factory.createReader(is) : factory.createReader(is, charset);
}
Also used : Charset(java.nio.charset.Charset) JsonReaderFactory(jakarta.json.JsonReaderFactory)

Example 2 with JsonReaderFactory

use of jakarta.json.JsonReaderFactory in project helidon by oracle.

the class WeldFeature method weldProxyConfigurations.

static List<WeldProxyConfig> weldProxyConfigurations(DuringSetupAccess access) {
    try {
        ClassLoader classLoader = access.findClassByName("io.helidon.config.Config").getClassLoader();
        Enumeration<URL> resources = classLoader.getResources("META-INF/helidon/native-image/weld-proxies.json");
        JsonReaderFactory readerFactory = Json.createReaderFactory(Map.of());
        List<WeldProxyConfig> weldProxies = new ArrayList<>();
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            JsonArray proxies;
            try {
                proxies = readerFactory.createReader(url.openStream()).readArray();
            } catch (JsonParsingException e) {
                throw new NativeImageException("Failed to read JSON config: " + url, e);
            }
            proxies.forEach(jsonValue -> {
                weldProxies.add(new WeldProxyConfig((JsonObject) jsonValue));
            });
        }
        return weldProxies;
    } catch (IOException e) {
        throw new IllegalStateException("Failed to get resources", e);
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(jakarta.json.JsonObject) IOException(java.io.IOException) URL(java.net.URL) JsonArray(jakarta.json.JsonArray) JsonReaderFactory(jakarta.json.JsonReaderFactory) JsonParsingException(jakarta.json.stream.JsonParsingException)

Example 3 with JsonReaderFactory

use of jakarta.json.JsonReaderFactory in project helidon by oracle.

the class HelidonReflectionConfiguration method load.

static HelidonReflectionConfiguration load(Feature.BeforeAnalysisAccess access, ClassLoader cl, NativeTrace tracer) {
    try {
        Enumeration<URL> resources = cl.getResources("META-INF/helidon/native-image/reflection-config.json");
        HelidonReflectionConfiguration config = new HelidonReflectionConfiguration();
        JsonReaderFactory readerFactory = Json.createReaderFactory(Map.of());
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            try {
                JsonObject configurationJson = readerFactory.createReader(url.openStream()).readObject();
                jsonArray(tracer, access, config.annotations, configurationJson.getJsonArray("annotated"), "Annotation");
                jsonArray(tracer, access, config.hierarchy, configurationJson.getJsonArray("class-hierarchy"), "Class hierarchy");
                jsonArray(tracer, access, config.fullHierarchy, configurationJson.getJsonArray("full-class-hierarchy"), "Full class hierarchy");
                jsonArray(tracer, access, config.classes, configurationJson.getJsonArray("classes"), "Single");
                jsonArray(tracer, access, config.excluded, configurationJson.getJsonArray("exclude"), "Exclude");
            } catch (JsonParsingException e) {
                System.err.println("Failed to process configuration file: " + url);
                throw e;
            }
        }
        return config;
    } catch (Exception e) {
        throw new IllegalStateException("Failed to process configuration from helidon-reflection-config.json files", e);
    }
}
Also used : JsonObject(jakarta.json.JsonObject) URL(java.net.URL) JsonParsingException(jakarta.json.stream.JsonParsingException) JsonReaderFactory(jakarta.json.JsonReaderFactory) JsonParsingException(jakarta.json.stream.JsonParsingException)

Example 4 with JsonReaderFactory

use of jakarta.json.JsonReaderFactory in project helidon by oracle.

the class ConfigMetadataMain method main.

/**
 * Start the example.
 * @param args ignored
 */
public static void main(String[] args) throws IOException {
    JsonReaderFactory readerFactory = Json.createReaderFactory(Map.of());
    Enumeration<URL> files = ConfigMetadataMain.class.getClassLoader().getResources("META-INF/helidon/config-metadata.json");
    List<ConfiguredType> configuredTypes = new LinkedList<>();
    Map<String, ConfiguredType> typesMap = new HashMap<>();
    while (files.hasMoreElements()) {
        URL url = files.nextElement();
        try (InputStream is = url.openStream()) {
            JsonReader reader = readerFactory.createReader(is, StandardCharsets.UTF_8);
            processMetadataJson(configuredTypes, typesMap, reader.readArray());
        }
    }
    for (ConfiguredType configuredType : configuredTypes) {
        if (configuredType.standalone()) {
            printType(configuredType, typesMap);
        }
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) JsonReader(jakarta.json.JsonReader) URL(java.net.URL) LinkedList(java.util.LinkedList) JsonReaderFactory(jakarta.json.JsonReaderFactory)

Aggregations

JsonReaderFactory (jakarta.json.JsonReaderFactory)4 URL (java.net.URL)3 JsonObject (jakarta.json.JsonObject)2 JsonParsingException (jakarta.json.stream.JsonParsingException)2 JsonArray (jakarta.json.JsonArray)1 JsonReader (jakarta.json.JsonReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1