use of com.fasterxml.jackson.databind.JsonMappingException in project x-pipe by ctripcorp.
the class ErrorMessageTest method testSerializa.
@Test
public void testSerializa() throws JsonParseException, JsonMappingException, IOException {
ErrorMessage<ERRORCODE> error = new ErrorMessage<ERRORCODE>(ERRORCODE.NET_EXCEPTION, "conntect refused");
String result = Codec.DEFAULT.encode(error);
logger.info("{}", result);
ObjectMapper om = new ObjectMapper();
ErrorMessage<ERRORCODE> desr = om.readValue(result, new TypeReference<ErrorMessage<ERRORCODE>>() {
});
Assert.assertEquals(error, desr);
desr = Codec.DEFAULT.decode(result, new GenericTypeReference<ErrorMessage<ERRORCODE>>() {
});
Assert.assertEquals(error, desr);
// test wrong message
try {
String wrong = "{\"errorType\":\"NET_EXCEPTION1\",\"errorMessage\":\"conntect refused\"}";
desr = om.readValue(wrong, new TypeReference<ErrorMessage<ERRORCODE>>() {
});
Assert.fail();
} catch (Exception e) {
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project presto by prestodb.
the class V9SegmentIndexSource method loadIndex.
@Override
public QueryableIndex loadIndex(List<ColumnHandle> columnHandles) throws IOException {
ByteBuffer indexBuffer = ByteBuffer.wrap(segmentColumnSource.getColumnData(INDEX_METADATA_FILE_NAME));
GenericIndexed.read(indexBuffer, STRING_STRATEGY);
GenericIndexed<String> allDimensions = GenericIndexed.read(indexBuffer, STRING_STRATEGY);
Interval dataInterval = Intervals.utc(indexBuffer.getLong(), indexBuffer.getLong());
BitmapSerdeFactory segmentBitmapSerdeFactory;
if (indexBuffer.hasRemaining()) {
segmentBitmapSerdeFactory = JSON_MAPPER.readValue(SERIALIZER_UTILS.readString(indexBuffer), BitmapSerdeFactory.class);
} else {
segmentBitmapSerdeFactory = new BitmapSerde.LegacyBitmapSerdeFactory();
}
Metadata metadata = null;
ByteBuffer metadataBuffer = ByteBuffer.wrap(segmentColumnSource.getColumnData(SEGMENT_METADATA_FILE_NAME));
try {
metadata = JSON_MAPPER.readValue(SERIALIZER_UTILS.readBytes(metadataBuffer, metadataBuffer.remaining()), Metadata.class);
} catch (JsonParseException | JsonMappingException e) {
// Any jackson deserialization errors are ignored e.g. if metadata contains some aggregator which
// is no longer supported then it is OK to not use the metadata instead of failing segment loading
log.warn(e, "Failed to load metadata for segment");
}
Map<String, Supplier<ColumnHolder>> columns = new HashMap<>();
for (ColumnHandle columnHandle : columnHandles) {
String columnName = ((DruidColumnHandle) columnHandle).getColumnName();
columns.put(columnName, () -> createColumnHolder(columnName));
}
List<String> availableDimensions = Streams.stream(allDimensions.iterator()).filter(columns::containsKey).collect(toImmutableList());
columns.put(TIME_COLUMN_NAME, () -> createColumnHolder(TIME_COLUMN_NAME));
Indexed<String> indexed = new ListIndexed<>(availableDimensions);
// TODO: get rid of the time column by creating Presto's SimpleQueryableIndex impl
return new SimpleQueryableIndex(dataInterval, indexed, segmentBitmapSerdeFactory.getBitmapFactory(), columns, null, metadata, false);
}
use of com.fasterxml.jackson.databind.JsonMappingException in project graylog2-server by Graylog2.
the class RetentionStrategyResource method getRetentionStrategyDescription.
private RetentionStrategyDescription getRetentionStrategyDescription(@ApiParam(name = "strategy", value = "The name of the retention strategy", required = true) @PathParam("strategy") @NotEmpty String strategyName) {
final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find retention strategy for given type " + strategyName);
}
final RetentionStrategy retentionStrategy = provider.get();
final RetentionStrategyConfig defaultConfig = retentionStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(retentionStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for retention strategy " + strategyName, e);
}
return RetentionStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
use of com.fasterxml.jackson.databind.JsonMappingException in project graylog2-server by Graylog2.
the class EncryptedValueDeserializer method parseFromDatabase.
private EncryptedValue parseFromDatabase(JsonParser p, JsonNode node) throws JsonProcessingException {
final JsonNode value = node.path("encrypted_value");
final JsonNode salt = node.path("salt");
if (value.isTextual() && salt.isTextual()) {
return EncryptedValue.builder().value(value.asText()).salt(salt.asText()).isKeepValue(false).isDeleteValue(false).build();
}
throw new JsonMappingException(p, "Couldn't deserialize value: " + node.toString() + " (encrypted_value and salt must be a strings and cannot missing)");
}
use of com.fasterxml.jackson.databind.JsonMappingException in project graylog2-server by Graylog2.
the class RotationStrategyResource method getRotationStrategyDescription.
private RotationStrategyDescription getRotationStrategyDescription(String strategyName) {
final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find rotation strategy for given type " + strategyName);
}
final RotationStrategy rotationStrategy = provider.get();
final RotationStrategyConfig defaultConfig = rotationStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(rotationStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for rotation strategy " + strategyName, e);
}
return RotationStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
Aggregations