Search in sources :

Example 66 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project spring-boot-admin by codecentric.

the class ApplicationTest method test_json_format.

@Test
public void test_json_format() throws JsonProcessingException, IOException {
    ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
    Application app = Application.create("test").withHealthUrl("http://health").withServiceUrl("http://service").withManagementUrl("http://management").build();
    DocumentContext json = JsonPath.parse(objectMapper.writeValueAsString(app));
    assertThat((String) json.read("$.name")).isEqualTo("test");
    assertThat((String) json.read("$.serviceUrl")).isEqualTo("http://service");
    assertThat((String) json.read("$.managementUrl")).isEqualTo("http://management");
    assertThat((String) json.read("$.healthUrl")).isEqualTo("http://health");
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Application(de.codecentric.boot.admin.client.registration.Application) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 67 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project cas by apereo.

the class RegisteredServiceJsonSerializer method initializeObjectMapper.

/**
     * Mixins are added to the object mapper in order to
     * ignore certain method signatures from serialization
     * that are otherwise treated as getters. Each mixin
     * implements the appropriate interface as a private
     * dummy class and is annotated with JsonIgnore elements
     * throughout. This helps us catch errors at compile-time
     * when the interface changes.
     *
     * @return the prepped object mapper.
     */
@Override
protected ObjectMapper initializeObjectMapper() {
    final ObjectMapper mapper = super.initializeObjectMapper();
    mapper.addHandler(new JasigRegisteredServiceDeserializationProblemHandler());
    return mapper;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 68 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class TargetsCommand method printJsonForTargets.

@VisibleForTesting
void printJsonForTargets(CommandRunnerParams params, ListeningExecutorService executor, Iterable<TargetNode<?, ?>> targetNodes, ImmutableMap<BuildTarget, ShowOptions> showRulesResult, ImmutableSet<String> outputAttributes) throws BuildFileParseException {
    PatternsMatcher attributesPatternsMatcher = new PatternsMatcher(outputAttributes);
    // Print the JSON representation of the build node for the specified target(s).
    params.getConsole().getStdOut().println("[");
    ObjectMapper mapper = params.getObjectMapper();
    Iterator<TargetNode<?, ?>> targetNodeIterator = targetNodes.iterator();
    while (targetNodeIterator.hasNext()) {
        TargetNode<?, ?> targetNode = targetNodeIterator.next();
        Map<String, Object> sortedTargetRule;
        sortedTargetRule = params.getParser().getRawTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, targetNode);
        if (sortedTargetRule == null) {
            params.getConsole().printErrorText("unable to find rule for target " + targetNode.getBuildTarget().getFullyQualifiedName());
            continue;
        }
        sortedTargetRule = attributesPatternsMatcher.filterMatchingMapKeys(sortedTargetRule);
        ShowOptions showOptions = showRulesResult.get(targetNode.getBuildTarget());
        if (showOptions != null) {
            putIfValuePresentAndMatches(ShowOptionsName.RULE_KEY.getName(), showOptions.getRuleKey(), sortedTargetRule, attributesPatternsMatcher);
            putIfValuePresentAndMatches(ShowOptionsName.OUTPUT_PATH.getName(), showOptions.getOutputPath(), sortedTargetRule, attributesPatternsMatcher);
            putIfValuePresentAndMatches(ShowOptionsName.TARGET_HASH.getName(), showOptions.getTargetHash(), sortedTargetRule, attributesPatternsMatcher);
        }
        String fullyQualifiedNameAttribute = "fully_qualified_name";
        if (attributesPatternsMatcher.matches(fullyQualifiedNameAttribute)) {
            sortedTargetRule.put(fullyQualifiedNameAttribute, targetNode.getBuildTarget().getFullyQualifiedName());
        }
        String cellPathAttribute = "buck.cell_path";
        if (isShowCellPath() && attributesPatternsMatcher.matches(cellPathAttribute)) {
            sortedTargetRule.put(cellPathAttribute, targetNode.getBuildTarget().getCellPath());
        }
        // Print the build rule information as JSON.
        StringWriter stringWriter = new StringWriter();
        try {
            mapper.writerWithDefaultPrettyPrinter().writeValue(stringWriter, sortedTargetRule);
        } catch (IOException e) {
            // Shouldn't be possible while writing to a StringWriter...
            throw new RuntimeException(e);
        }
        String output = stringWriter.getBuffer().toString();
        if (targetNodeIterator.hasNext()) {
            output += ",";
        }
        params.getConsole().getStdOut().println(output);
    }
    params.getConsole().getStdOut().println("]");
}
Also used : PatternsMatcher(com.facebook.buck.util.PatternsMatcher) TargetNode(com.facebook.buck.rules.TargetNode) StringWriter(java.io.StringWriter) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 69 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class BuckEventsHandlerTest method testResultSummaryExternalInterfaceKnowsResultType.

@Test
public void testResultSummaryExternalInterfaceKnowsResultType() throws Exception {
    final String json = "{\n" + "    \"testCaseName\": \"ok.api.ApiTest\",\n" + "    \"type\": \"FAILURE\",\n" + "    \"time\": 3348,\n" + "    \"message\": null,\n" + "    \"stacktrace\": null,\n" + "    \"stdOut\": \"sup from test stdout\",\n" + "    \"stdErr\": null,\n" + "    \"testName\": \"logoutAll\"\n" + "}";
    final ObjectMapper objectMapper = BuckEventsHandler.createObjectMapper();
    final TestResultSummaryExternalInterface res = objectMapper.readValue(json, TestResultSummaryExternalInterface.class);
    // because it is @JsonIgnore'd
    assertFalse(res.isSuccess());
    assertEquals(ResultType.FAILURE, res.getType());
}
Also used : TestResultSummaryExternalInterface(com.facebook.buck.event.external.elements.TestResultSummaryExternalInterface) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 70 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class ArtifactConfig method fromCommandLineArgs.

public static ArtifactConfig fromCommandLineArgs(String[] args) throws CmdLineException, IOException {
    CmdLineArgs parsedArgs = new CmdLineArgs();
    CmdLineParser parser = new CmdLineParser(parsedArgs);
    parser.parseArgument(args);
    if (parsedArgs.showHelp) {
        usage(parser);
    }
    ArtifactConfig artifactConfig;
    // If the -config argument was specified, load a config from JSON.
    if (parsedArgs.artifactConfigJson != null) {
        ObjectMapper mapper = new ObjectMapper();
        File jsonFile = new File(parsedArgs.artifactConfigJson);
        artifactConfig = mapper.readValue(jsonFile, ArtifactConfig.class);
    } else {
        artifactConfig = new ArtifactConfig();
    }
    if (artifactConfig.buckRepoRoot == null && parsedArgs.buckRepoRoot == null) {
        usage(parser);
    }
    artifactConfig.mergeCmdLineArgs(parsedArgs);
    return artifactConfig;
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6071 Test (org.junit.Test)2235 IOException (java.io.IOException)1016 JsonNode (com.fasterxml.jackson.databind.JsonNode)930 HashMap (java.util.HashMap)444 Map (java.util.Map)429 ArrayList (java.util.ArrayList)416 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)388 File (java.io.File)319 List (java.util.List)268 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)254 Before (org.junit.Before)246 Test (org.junit.jupiter.api.Test)238 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 InputStream (java.io.InputStream)185 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)156 Matchers.containsString (org.hamcrest.Matchers.containsString)136 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)123 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)121