Search in sources :

Example 51 with JsonMappingException

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) {
    }
}
Also used : GenericTypeReference(com.ctrip.xpipe.api.codec.GenericTypeReference) GenericTypeReference(com.ctrip.xpipe.api.codec.GenericTypeReference) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 52 with JsonMappingException

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);
}
Also used : DruidColumnHandle(com.facebook.presto.druid.DruidColumnHandle) DruidColumnHandle(com.facebook.presto.druid.DruidColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ListIndexed(org.apache.druid.segment.data.ListIndexed) HashMap(java.util.HashMap) BitmapSerde(org.apache.druid.segment.data.BitmapSerde) Metadata(org.apache.druid.segment.Metadata) SimpleQueryableIndex(org.apache.druid.segment.SimpleQueryableIndex) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ByteBuffer(java.nio.ByteBuffer) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Supplier(com.google.common.base.Supplier) BitmapSerdeFactory(org.apache.druid.segment.data.BitmapSerdeFactory) Interval(org.joda.time.Interval)

Example 53 with JsonMappingException

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());
}
Also used : RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) RetentionStrategy(org.graylog2.plugin.indexer.retention.RetentionStrategy) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) NotFoundException(javax.ws.rs.NotFoundException) SchemaFactoryWrapper(com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper) InternalServerErrorException(javax.ws.rs.InternalServerErrorException)

Example 54 with JsonMappingException

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)");
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 55 with JsonMappingException

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());
}
Also used : RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) NotFoundException(javax.ws.rs.NotFoundException) SchemaFactoryWrapper(com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper) InternalServerErrorException(javax.ws.rs.InternalServerErrorException)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)140 IOException (java.io.IOException)68 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 JsonParseException (com.fasterxml.jackson.core.JsonParseException)52 Test (org.junit.Test)31 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)19 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)14 Map (java.util.Map)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 File (java.io.File)9 InputStream (java.io.InputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 List (java.util.List)7 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 Response (javax.ws.rs.core.Response)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)5