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);
}
}
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);
}
}
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));
}
});
}
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");
}
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));
}
Aggregations