Search in sources :

Example 16 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project repseqio by repseqio.

the class VDJCGeneTest method jsonTestNoCurrentLibrary1.

@Test
public void jsonTestNoCurrentLibrary1() throws Exception {
    VDJCLibrary library = VDJCLibraryRegistry.getDefaultLibrary("hs");
    VDJCGene gene = library.getSafe("TRBV12-3*00");
    ObjectWriter writer = GlobalObjectMappers.PRETTY.writerFor(VDJCGene.class);
    ObjectReader reader = GlobalObjectMappers.PRETTY.readerFor(VDJCGene.class);
    String str = writer.writeValueAsString(gene);
    assertTrue(str.endsWith("/TRBV12-3*00\""));
    Object geneDeserialized = reader.readValue(str);
    assertTrue(geneDeserialized == gene);
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.Test)

Example 17 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project cloudbreak by hortonworks.

the class TenantChecker method checkTenant.

public void checkTenant(String tenantId, String accessToken) throws InteractiveLoginException {
    if (tenantId == null) {
        throw new InteractiveLoginException("Parameter tenantId is required and cannot be null.");
    }
    Client client = ClientBuilder.newClient();
    WebTarget resource = client.target(AZURE_MANAGEMENT);
    Builder request = resource.path("/tenants").queryParam("api-version", "2016-06-01").request();
    request.accept(MediaType.APPLICATION_JSON);
    request.header("Authorization", "Bearer " + accessToken);
    Response response = request.get();
    if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
        String entity = response.readEntity(String.class);
        try {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode tenantArray = mapper.readTree(entity).get("value");
            ObjectReader reader = mapper.readerFor(new TypeReference<ArrayList<AzureTenant>>() {
            });
            List<AzureTenant> tenants = reader.readValue(tenantArray);
            for (AzureTenant tenant : tenants) {
                if (tenant.getTenantId().equals(tenantId)) {
                    LOGGER.debug("Tenant definitions successfully retrieved:" + tenant.getTenantId());
                    return;
                }
            }
        } catch (IOException e) {
            throw new InteractiveLoginException(e.toString());
        }
        throw new InteractiveLoginException("Tenant specified in Profile file not found with id: " + tenantId);
    } else {
        String errorResponse = response.readEntity(String.class);
        try {
            String errorMessage = new ObjectMapper().readTree(errorResponse).get("error").get("message").asText();
            LOGGER.error("Tenant retrieve error:" + errorMessage);
            throw new InteractiveLoginException("Error with the tenant specified in Profile file id: " + tenantId + ", message: " + errorMessage);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}
Also used : ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Response(javax.ws.rs.core.Response) AzureTenant(com.sequenceiq.cloudbreak.cloud.azure.AzureTenant) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 18 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project onebusaway-application-modules by camsys.

the class CustomJacksonLibHandler method toObject.

public void toObject(Reader in, Object target) throws IOException {
    mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    ObjectReader or = mapper.readerForUpdating(target);
    // , new TypeReference<clazz>);
    or.readValue(in);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 19 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project nzbhydra2 by theotherp.

the class AbstractConfigReplacingTest method replaceConfig.

public void replaceConfig(URL resource) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.writeValueAsString(baseConfig);
    ObjectReader updater = objectMapper.readerForUpdating(baseConfig);
    BaseConfig updatedConfig = updater.readValue(resource);
    baseConfig.replace(updatedConfig);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) BaseConfig(org.nzbhydra.config.BaseConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project logging-log4j2 by apache.

the class LevelMixInTest method testContainer.

@Test
public void testContainer() throws IOException {
    final Fixture expected = new Fixture();
    final String str = writer.writeValueAsString(expected);
    Assert.assertTrue(str.contains("DEBUG"));
    final ObjectReader fixtureReader = log4jObjectMapper.readerFor(Fixture.class);
    final Fixture actual = fixtureReader.readValue(str);
    Assert.assertEquals(expected, actual);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.Test)

Aggregations

ObjectReader (com.fasterxml.jackson.databind.ObjectReader)83 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 IOException (java.io.IOException)32 Test (org.junit.Test)23 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ArrayList (java.util.ArrayList)8 JavaType (com.fasterxml.jackson.databind.JavaType)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)4 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)4 Method (java.lang.reflect.Method)4 Collectors (java.util.stream.Collectors)4 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)3 JSONLayoutPage (org.knime.js.core.layout.bs.JSONLayoutPage)3