Search in sources :

Example 1 with ObjectMapper

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

the class GenStringSourceMapStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) {
    // Read the R.txt file that was generated by aapt during GenRDotTxtUtil.
    // This file contains all the resource names and the integer id that aapt assigned.
    Path rDotTxtPath = rDotTxtDir.resolve("R.txt");
    try {
        CompileStringsStep.buildResourceNameToIdMap(filesystem, rDotTxtPath, stringResourceNameToIdMap, pluralsResourceNameToIdMap, arrayResourceNameToIdMap);
    } catch (FileNotFoundException ex) {
        context.logError(ex, "The '%s' file is not present.", rDotTxtPath);
        return StepExecutionResult.ERROR;
    } catch (IOException ex) {
        context.logError(ex, "Failure parsing R.txt file.");
        return StepExecutionResult.ERROR;
    }
    Map<String, Map<String, NativeResourceInfo>> nativeStrings = parseStringFiles(context);
    // write nativeStrings out to a file
    Path outputPath = destinationPath.resolve("strings.json");
    try {
        ObjectMapper mapper = ObjectMappers.newDefaultInstance();
        mapper.writeValue(filesystem.getPathForRelativePath(outputPath).toFile(), nativeStrings);
    } catch (IOException ex) {
        context.logError(ex, "Failed when trying to save the output file: '%s'", outputPath.toString());
        return StepExecutionResult.ERROR;
    }
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ObjectMapper

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

the class BuildReport method generateJsonBuildReport.

public String generateJsonBuildReport() throws IOException {
    Map<BuildRule, Optional<BuildResult>> ruleToResult = buildExecutionResult.getResults();
    LinkedHashMap<String, Object> results = Maps.newLinkedHashMap();
    LinkedHashMap<String, Object> failures = Maps.newLinkedHashMap();
    boolean isOverallSuccess = true;
    for (Map.Entry<BuildRule, Optional<BuildResult>> entry : ruleToResult.entrySet()) {
        BuildRule rule = entry.getKey();
        Optional<BuildRuleSuccessType> success = Optional.empty();
        Optional<BuildResult> result = entry.getValue();
        if (result.isPresent()) {
            success = Optional.ofNullable(result.get().getSuccess());
        }
        Map<String, Object> value = Maps.newLinkedHashMap();
        boolean isSuccess = success.isPresent();
        value.put("success", isSuccess);
        if (!isSuccess) {
            isOverallSuccess = false;
        }
        if (isSuccess) {
            value.put("type", success.get().name());
            SourcePath outputFile = rule.getSourcePathToOutput();
            value.put("output", outputFile != null ? pathResolver.getRelativePath(outputFile).toString() : null);
        }
        results.put(rule.getFullyQualifiedName(), value);
    }
    for (BuildResult failureResult : buildExecutionResult.getFailures()) {
        Throwable failure = Preconditions.checkNotNull(failureResult.getFailure());
        failures.put(failureResult.getRule().getFullyQualifiedName(), failure.getMessage());
    }
    Map<String, Object> report = Maps.newLinkedHashMap();
    report.put("success", isOverallSuccess);
    report.put("results", results);
    report.put("failures", failures);
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    return objectMapper.writeValueAsString(report);
}
Also used : Optional(java.util.Optional) SourcePath(com.facebook.buck.rules.SourcePath) BuildResult(com.facebook.buck.rules.BuildResult) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) BuildRule(com.facebook.buck.rules.BuildRule) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class NoneShardSpecTest method testPartitionFieldIgnored.

@Test
public void testPartitionFieldIgnored() throws IOException {
    final String jsonStr = "{\"type\": \"none\",\"partitionNum\": 2}";
    ObjectMapper mapper = new TestObjectMapper();
    final ShardSpec noneShardSpec = mapper.readValue(jsonStr, ShardSpec.class);
    noneShardSpec.equals(NoneShardSpec.instance());
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TestObjectMapper(io.druid.TestObjectMapper) TestObjectMapper(io.druid.TestObjectMapper) Test(org.junit.Test)

Example 4 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class SketchEstimateWithErrorBoundsTest method testSerde.

@Test
public void testSerde() throws IOException {
    ObjectMapper mapper = new DefaultObjectMapper();
    SketchEstimateWithErrorBounds est = new SketchEstimateWithErrorBounds(100.0, 101.5, 98.5, 2);
    Assert.assertEquals(est, mapper.readValue(mapper.writeValueAsString(est), SketchEstimateWithErrorBounds.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.

the class AuthenticationKerberosConfigTest method testserde.

@Test
public void testserde() {
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
            binder.install(new ConfigModule());
            binder.install(new DruidGuiceExtensions());
            JsonConfigProvider.bind(binder, "druid.hadoop.security.kerberos", AuthenticationKerberosConfig.class);
        }

        @Provides
        @LazySingleton
        public ObjectMapper jsonMapper() {
            return new DefaultObjectMapper();
        }
    });
    Properties props = injector.getInstance(Properties.class);
    AuthenticationKerberosConfig config = injector.getInstance(AuthenticationKerberosConfig.class);
    Assert.assertEquals(props.getProperty("druid.hadoop.security.kerberos.principal"), config.getPrincipal());
    Assert.assertEquals(props.getProperty("druid.hadoop.security.kerberos.keytab"), config.getKeytab());
}
Also used : DruidGuiceExtensions(io.druid.guice.DruidGuiceExtensions) ConfigModule(io.druid.guice.ConfigModule) Provides(com.google.inject.Provides) Properties(java.util.Properties) Binder(com.google.inject.Binder) LazySingleton(io.druid.guice.LazySingleton) Injector(com.google.inject.Injector) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Module(com.google.inject.Module) PropertiesModule(io.druid.guice.PropertiesModule) ConfigModule(io.druid.guice.ConfigModule) PropertiesModule(io.druid.guice.PropertiesModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5550 Test (org.junit.Test)2025 IOException (java.io.IOException)907 JsonNode (com.fasterxml.jackson.databind.JsonNode)761 HashMap (java.util.HashMap)398 Map (java.util.Map)391 ArrayList (java.util.ArrayList)373 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)338 File (java.io.File)299 List (java.util.List)244 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)228 Test (org.junit.jupiter.api.Test)226 Before (org.junit.Before)208 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 InputStream (java.io.InputStream)157 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)138 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Matchers.containsString (org.hamcrest.Matchers.containsString)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)115 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)108