Search in sources :

Example 21 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project azure-tools-for-java by Microsoft.

the class AzureSdkCategoryService method loadAzureSDKCategories.

@Cacheable(value = "azure-sdk-category-entities")
@AzureOperation(name = "sdk.load_category_data", type = AzureOperation.Type.TASK)
public static Map<String, List<AzureSdkCategoryEntity>> loadAzureSDKCategories() {
    try (final InputStream stream = AzureSdkCategoryService.class.getResourceAsStream(SERVICE_CATEGORY_CSV)) {
        // read
        final ObjectReader reader = CSV_MAPPER.readerFor(AzureSdkCategoryEntity.class).with(CsvSchema.emptySchema().withHeader());
        final MappingIterator<AzureSdkCategoryEntity> data = reader.readValues(stream);
        final List<AzureSdkCategoryEntity> categories = data.readAll();
        // default category & description suffix.
        categories.stream().filter(c -> StringUtils.isNotBlank(c.getServiceName())).forEach(c -> {
            if (StringUtils.isBlank(c.getCategory())) {
                c.setCategory("Others");
            }
            final String trimDescription = StringUtils.trim(c.getDescription());
            if (StringUtils.isNotBlank(trimDescription) && !StringUtils.endsWith(trimDescription, ".")) {
                c.setDescription(trimDescription + ".");
            }
        });
        // unique
        final List<AzureSdkCategoryEntity> uniqueCategories = categories.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getCategory() + "," + o.getServiceName()))), ArrayList::new));
        // group
        return uniqueCategories.stream().collect(Collectors.groupingBy(AzureSdkCategoryEntity::getCategory));
    } catch (final IOException e) {
        final String message = String.format("failed to load Azure SDK categories from \"%s\"", SERVICE_CATEGORY_CSV);
        throw new AzureToolkitRuntimeException(message, e);
    }
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) List(java.util.List) Map(java.util.Map) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) Comparator(java.util.Comparator) InputStream(java.io.InputStream) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) InputStream(java.io.InputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 22 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project spring-framework by spring-projects.

the class AbstractJackson2Decoder method decode.

@Override
public Object decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException {
    ObjectMapper mapper = selectObjectMapper(targetType, mimeType);
    if (mapper == null) {
        throw new IllegalStateException("No ObjectMapper for " + targetType);
    }
    try {
        ObjectReader objectReader = getObjectReader(mapper, targetType, hints);
        Object value = objectReader.readValue(dataBuffer.asInputStream());
        logValue(value, hints);
        return value;
    } catch (IOException ex) {
        throw processException(ex);
    } finally {
        DataBufferUtils.release(dataBuffer);
    }
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project spring-framework by spring-projects.

the class AbstractJackson2Decoder method decode.

@Override
public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
    ObjectMapper mapper = selectObjectMapper(elementType, mimeType);
    if (mapper == null) {
        throw new IllegalStateException("No ObjectMapper for " + elementType);
    }
    boolean forceUseOfBigDecimal = mapper.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
    if (BigDecimal.class.equals(elementType.getType())) {
        forceUseOfBigDecimal = true;
    }
    Flux<DataBuffer> processed = processInput(input, elementType, mimeType, hints);
    Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(processed, mapper.getFactory(), mapper, true, forceUseOfBigDecimal, getMaxInMemorySize());
    ObjectReader reader = getObjectReader(mapper, elementType, hints);
    return tokens.handle((tokenBuffer, sink) -> {
        try {
            Object value = reader.readValue(tokenBuffer.asParser(mapper));
            logValue(value, hints);
            if (value != null) {
                sink.next(value);
            }
        } catch (IOException ex) {
            sink.error(processException(ex));
        }
    });
}
Also used : TokenBuffer(com.fasterxml.jackson.databind.util.TokenBuffer) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Example 24 with ObjectReader

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

the class ParanamerModuleTest method deserializePersonWithoutAnnotations.

@Test
void deserializePersonWithoutAnnotations() throws IOException {
    final ObjectReader reader = mapper.readerFor(Person.class);
    final Person person = reader.readValue("{ \"name\": \"Foo\", \"surname\": \"Bar\" }");
    assertThat(person.getName()).isEqualTo("Foo");
    assertThat(person.getSurname()).isEqualTo("Bar");
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.jupiter.api.Test)

Example 25 with ObjectReader

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

the class RexWindowBoundSerdeTest method testSerde.

@Test
public void testSerde() throws IOException {
    SerdeContext serdeCtx = new SerdeContext(null, new FlinkContextImpl(false, TableConfig.getDefault(), new ModuleManager(), null, CatalogManagerMocks.createEmptyCatalogManager(), null), Thread.currentThread().getContextClassLoader(), FlinkTypeFactory.INSTANCE(), FlinkSqlOperatorTable.instance());
    ObjectReader objectReader = JsonSerdeUtil.createObjectReader(serdeCtx);
    ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
    assertEquals(RexWindowBounds.CURRENT_ROW, objectReader.readValue(objectWriter.writeValueAsString(RexWindowBounds.CURRENT_ROW), RexWindowBound.class));
    assertEquals(RexWindowBounds.UNBOUNDED_FOLLOWING, objectReader.readValue(objectWriter.writeValueAsString(RexWindowBounds.UNBOUNDED_FOLLOWING), RexWindowBound.class));
    assertEquals(RexWindowBounds.UNBOUNDED_PRECEDING, objectReader.readValue(objectWriter.writeValueAsString(RexWindowBounds.UNBOUNDED_PRECEDING), RexWindowBound.class));
    RexBuilder builder = new RexBuilder(FlinkTypeFactory.INSTANCE());
    RexWindowBound windowBound = RexWindowBounds.following(builder.makeLiteral("test"));
    assertEquals(windowBound, objectReader.readValue(objectWriter.writeValueAsString(windowBound), RexWindowBound.class));
    windowBound = RexWindowBounds.preceding(builder.makeLiteral("test"));
    assertEquals(windowBound, objectReader.readValue(objectWriter.writeValueAsString(windowBound), RexWindowBound.class));
}
Also used : FlinkContextImpl(org.apache.flink.table.planner.calcite.FlinkContextImpl) RexWindowBound(org.apache.calcite.rex.RexWindowBound) ObjectWriter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter) RexBuilder(org.apache.calcite.rex.RexBuilder) ObjectReader(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader) ModuleManager(org.apache.flink.table.module.ModuleManager) 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