Search in sources :

Example 41 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project azure-sdk-for-java by Azure.

the class DeployUsingARMTemplateWithProgress method getTemplate.

private static String getTemplate() throws IllegalAccessException, JsonProcessingException, IOException {
    final String hostingPlanName = SdkContext.randomResourceName("hpRSAT", 24);
    final String webappName = SdkContext.randomResourceName("wnRSAT", 24);
    final InputStream embeddedTemplate;
    embeddedTemplate = DeployUsingARMTemplateWithProgress.class.getResourceAsStream("/templateValue.json");
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode tmp = mapper.readTree(embeddedTemplate);
    DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", hostingPlanName, "hostingPlanName", null, tmp);
    DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", webappName, "webSiteName", null, tmp);
    DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("string", "F1", "skuName", null, tmp);
    DeployUsingARMTemplateWithProgress.validateAndAddFieldValue("int", "1", "skuCapacity", null, tmp);
    return tmp.toString();
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 42 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project vscode-nextgenas by BowlerHatLLC.

the class ASConfigProjectConfigStrategy method getOptions.

public ProjectOptions getOptions() {
    changed = false;
    if (asconfigPath == null) {
        return null;
    }
    File asconfigFile = asconfigPath.toFile();
    if (!asconfigFile.exists()) {
        return null;
    }
    Path projectRoot = asconfigPath.getParent();
    ProjectType type = ProjectType.APP;
    String config = "flex";
    String[] files = null;
    String additionalOptions = null;
    CompilerOptions compilerOptions = new CompilerOptions();
    try (InputStream schemaInputStream = getClass().getResourceAsStream("/schemas/asconfig.schema.json")) {
        JsonSchemaFactory factory = new JsonSchemaFactory();
        JsonSchema schema = factory.getSchema(schemaInputStream);
        String contents = FileUtils.readFileToString(asconfigFile);
        ObjectMapper mapper = new ObjectMapper();
        //VSCode allows comments, so we should too
        mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
        JsonNode json = mapper.readTree(contents);
        Set<ValidationMessage> errors = schema.validate(json);
        if (!errors.isEmpty()) {
            System.err.println("Failed to validate asconfig.json.");
            for (ValidationMessage error : errors) {
                System.err.println(error.toString());
            }
            return null;
        } else {
            if (//optional, defaults to "app"
            json.has(ProjectOptions.TYPE)) {
                String typeString = json.get(ProjectOptions.TYPE).asText();
                type = ProjectType.fromToken(typeString);
            }
            if (//optional, defaults to "flex"
            json.has(ProjectOptions.CONFIG)) {
                config = json.get(ProjectOptions.CONFIG).asText();
            }
            if (//optional
            json.has(ProjectOptions.FILES)) {
                JsonNode jsonFiles = json.get(ProjectOptions.FILES);
                int fileCount = jsonFiles.size();
                files = new String[fileCount];
                for (int i = 0; i < fileCount; i++) {
                    String pathString = jsonFiles.get(i).asText();
                    Path filePath = projectRoot.resolve(pathString);
                    files[i] = filePath.toString();
                }
            }
            if (//optional
            json.has(ProjectOptions.COMPILER_OPTIONS)) {
                JsonNode jsonCompilerOptions = json.get(ProjectOptions.COMPILER_OPTIONS);
                if (jsonCompilerOptions.has(CompilerOptions.DEBUG)) {
                    compilerOptions.debug = jsonCompilerOptions.get(CompilerOptions.DEBUG).asBoolean();
                }
                if (jsonCompilerOptions.has(CompilerOptions.DEFINE)) {
                    HashMap<String, String> defines = new HashMap<>();
                    JsonNode jsonDefine = jsonCompilerOptions.get(CompilerOptions.DEFINE);
                    for (int i = 0, count = jsonDefine.size(); i < count; i++) {
                        JsonNode jsonNamespace = jsonDefine.get(i);
                        String name = jsonNamespace.get(CompilerOptions.DEFINE_NAME).asText();
                        JsonNode jsonValue = jsonNamespace.get(CompilerOptions.DEFINE_VALUE);
                        String value = jsonValue.asText();
                        if (jsonValue.isTextual()) {
                            value = "\"" + value + "\"";
                        }
                        defines.put(name, value.toString());
                    }
                    compilerOptions.defines = defines;
                }
                if (jsonCompilerOptions.has(CompilerOptions.EXTERNAL_LIBRARY_PATH)) {
                    JsonNode jsonExternalLibraryPath = jsonCompilerOptions.get(CompilerOptions.EXTERNAL_LIBRARY_PATH);
                    compilerOptions.externalLibraryPath = jsonPathsToList(jsonExternalLibraryPath, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.JS_EXTERNAL_LIBRARY_PATH)) {
                    JsonNode jsonExternalLibraryPath = jsonCompilerOptions.get(CompilerOptions.JS_EXTERNAL_LIBRARY_PATH);
                    compilerOptions.jsExternalLibraryPath = jsonPathsToList(jsonExternalLibraryPath, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.SWF_EXTERNAL_LIBRARY_PATH)) {
                    JsonNode jsonExternalLibraryPath = jsonCompilerOptions.get(CompilerOptions.SWF_EXTERNAL_LIBRARY_PATH);
                    compilerOptions.swfExternalLibraryPath = jsonPathsToList(jsonExternalLibraryPath, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.INCLUDE_CLASSES)) {
                    JsonNode jsonIncludeClasses = jsonCompilerOptions.get(CompilerOptions.INCLUDE_CLASSES);
                    ArrayList<String> includeClasses = new ArrayList<>();
                    for (int i = 0, count = jsonIncludeClasses.size(); i < count; i++) {
                        String qualifiedName = jsonIncludeClasses.get(i).asText();
                        includeClasses.add(qualifiedName);
                    }
                    compilerOptions.includeClasses = includeClasses;
                }
                if (jsonCompilerOptions.has(CompilerOptions.INCLUDE_NAMESPACES)) {
                    JsonNode jsonIncludeNamespaces = jsonCompilerOptions.get(CompilerOptions.INCLUDE_NAMESPACES);
                    ArrayList<String> includeNamespaces = new ArrayList<>();
                    for (int i = 0, count = jsonIncludeNamespaces.size(); i < count; i++) {
                        String namespaceURI = jsonIncludeNamespaces.get(i).asText();
                        includeNamespaces.add(namespaceURI);
                    }
                    compilerOptions.includeNamespaces = includeNamespaces;
                }
                if (jsonCompilerOptions.has(CompilerOptions.INCLUDE_SOURCES)) {
                    JsonNode jsonIncludeSources = jsonCompilerOptions.get(CompilerOptions.INCLUDE_SOURCES);
                    compilerOptions.includeSources = jsonPathsToList(jsonIncludeSources, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.JS_OUTPUT_TYPE)) {
                    String jsonJSOutputType = jsonCompilerOptions.get(CompilerOptions.JS_OUTPUT_TYPE).asText();
                    compilerOptions.jsOutputType = jsonJSOutputType;
                }
                if (jsonCompilerOptions.has(CompilerOptions.NAMESPACE)) {
                    JsonNode jsonLibraryPath = jsonCompilerOptions.get(CompilerOptions.NAMESPACE);
                    ArrayList<MXMLNamespaceMapping> namespaceMappings = new ArrayList<>();
                    for (int i = 0, count = jsonLibraryPath.size(); i < count; i++) {
                        JsonNode jsonNamespace = jsonLibraryPath.get(i);
                        String uri = jsonNamespace.get(CompilerOptions.NAMESPACE_URI).asText();
                        String manifest = jsonNamespace.get(CompilerOptions.NAMESPACE_MANIFEST).asText();
                        MXMLNamespaceMapping mapping = new MXMLNamespaceMapping(uri, manifest);
                        namespaceMappings.add(mapping);
                    }
                    compilerOptions.namespaceMappings = namespaceMappings;
                }
                if (jsonCompilerOptions.has(CompilerOptions.LIBRARY_PATH)) {
                    JsonNode jsonLibraryPath = jsonCompilerOptions.get(CompilerOptions.LIBRARY_PATH);
                    compilerOptions.libraryPath = jsonPathsToList(jsonLibraryPath, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.JS_LIBRARY_PATH)) {
                    JsonNode jsonLibraryPath = jsonCompilerOptions.get(CompilerOptions.JS_LIBRARY_PATH);
                    compilerOptions.jsLibraryPath = jsonPathsToList(jsonLibraryPath, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.SWF_LIBRARY_PATH)) {
                    JsonNode jsonLibraryPath = jsonCompilerOptions.get(CompilerOptions.SWF_LIBRARY_PATH);
                    compilerOptions.swfLibraryPath = jsonPathsToList(jsonLibraryPath, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.SOURCE_PATH)) {
                    JsonNode jsonSourcePath = jsonCompilerOptions.get(CompilerOptions.SOURCE_PATH);
                    compilerOptions.sourcePath = jsonPathsToList(jsonSourcePath, projectRoot);
                }
                if (jsonCompilerOptions.has(CompilerOptions.TARGETS)) {
                    JsonNode jsonTargets = jsonCompilerOptions.get(CompilerOptions.TARGETS);
                    ArrayList<String> targets = new ArrayList<>();
                    for (int i = 0, count = jsonTargets.size(); i < count; i++) {
                        String target = jsonTargets.get(i).asText();
                        targets.add(target);
                    }
                    compilerOptions.targets = targets;
                }
                if (jsonCompilerOptions.has(CompilerOptions.WARNINGS)) {
                    compilerOptions.warnings = jsonCompilerOptions.get(CompilerOptions.WARNINGS).asBoolean();
                }
            }
            //these options are formatted as if sent in through the command line
            if (//optional
            json.has(ProjectOptions.ADDITIONAL_OPTIONS)) {
                additionalOptions = json.get(ProjectOptions.ADDITIONAL_OPTIONS).asText();
            }
        }
    } catch (Exception e) {
        System.err.println("Failed to parse asconfig.json: " + e);
        e.printStackTrace();
        return null;
    }
    //include-sources compiler option
    if (type == ProjectType.LIB && files != null) {
        if (compilerOptions.includeSources == null) {
            compilerOptions.includeSources = new ArrayList<>();
        }
        for (int i = 0, count = files.length; i < count; i++) {
            String filePath = files[i];
            compilerOptions.includeSources.add(new File(filePath));
        }
        files = null;
    }
    ProjectOptions options = new ProjectOptions();
    options.type = type;
    options.config = config;
    options.files = files;
    options.compilerOptions = compilerOptions;
    options.additionalOptions = additionalOptions;
    return options;
}
Also used : Path(java.nio.file.Path) ValidationMessage(com.networknt.schema.ValidationMessage) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JsonSchema(com.networknt.schema.JsonSchema) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonSchemaFactory(com.networknt.schema.JsonSchemaFactory) MXMLNamespaceMapping(org.apache.flex.compiler.internal.mxml.MXMLNamespaceMapping) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 43 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project azure-sdk-for-java by Azure.

the class LinuxDiskVolumeEncryptionMonitorImpl method osDiskStatus.

@Override
public EncryptionStatus osDiskStatus() {
    if (!hasEncryptionExtension()) {
        return EncryptionStatus.NOT_ENCRYPTED;
    }
    final JsonNode subStatusNode = instanceViewFirstSubStatus();
    if (subStatusNode == null) {
        return EncryptionStatus.UNKNOWN;
    }
    JsonNode diskNode = subStatusNode.path("os");
    if (diskNode instanceof MissingNode) {
        return EncryptionStatus.UNKNOWN;
    }
    return EncryptionStatus.fromString(diskNode.asText());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode)

Example 44 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project jackson-databind by FasterXML.

the class RaceCondition738Test method runOnce.

void runOnce(int round, int max) throws Exception {
    final ObjectMapper mapper = getObjectMapper();
    Callable<String> writeJson = new Callable<String>() {

        @Override
        public String call() throws Exception {
            Wrapper wrapper = new Wrapper(new TypeOne("test"));
            return mapper.writeValueAsString(wrapper);
        }
    };
    int numThreads = 4;
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    List<Future<String>> jsonFutures = new ArrayList<Future<String>>();
    for (int i = 0; i < numThreads; i++) {
        jsonFutures.add(executor.submit(writeJson));
    }
    executor.shutdown();
    executor.awaitTermination(5, TimeUnit.SECONDS);
    for (Future<String> jsonFuture : jsonFutures) {
        String json = jsonFuture.get();
        JsonNode tree = mapper.readTree(json);
        JsonNode wrapped = tree.get("hasSubTypes");
        if (!wrapped.has("one")) {
            throw new IllegalStateException("Round #" + round + "/" + max + " ; missing property 'one', source: " + json);
        }
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 45 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project jackson-databind by FasterXML.

the class ArrayNode method serializeWithType.

@Override
public void serializeWithType(JsonGenerator jg, SerializerProvider provider, TypeSerializer typeSer) throws IOException {
    typeSer.writeTypePrefixForArray(this, jg);
    for (JsonNode n : _children) {
        ((BaseJsonNode) n).serialize(jg, provider);
    }
    typeSer.writeTypeSuffixForArray(this, jg);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4105 Test (org.junit.Test)1257 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)802 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)544 IOException (java.io.IOException)532 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)384 ArrayList (java.util.ArrayList)315 Test (org.junit.jupiter.api.Test)277 HashMap (java.util.HashMap)249 Map (java.util.Map)201 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)127 List (java.util.List)122 InputStream (java.io.InputStream)116 KernelTest (com.twosigma.beakerx.KernelTest)114 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)84 Response (javax.ws.rs.core.Response)79 File (java.io.File)78 HttpGet (org.apache.http.client.methods.HttpGet)75 ByteArrayInputStream (java.io.ByteArrayInputStream)70