Search in sources :

Example 41 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project rdf4j by eclipse.

the class JSONLDWriter method endRDF.

@Override
public void endRDF() throws RDFHandlerException {
    final JSONLDInternalRDFParser serialiser = new JSONLDInternalRDFParser();
    try {
        Object output = JsonLdProcessor.fromRDF(model, serialiser);
        final JSONLDMode mode = getWriterConfig().get(JSONLDSettings.JSONLD_MODE);
        final JsonLdOptions opts = new JsonLdOptions();
        // opts.addBlankNodeIDs =
        // getWriterConfig().get(BasicParserSettings.PRESERVE_BNODE_IDS);
        opts.setUseRdfType(getWriterConfig().get(JSONLDSettings.USE_RDF_TYPE));
        opts.setUseNativeTypes(getWriterConfig().get(JSONLDSettings.USE_NATIVE_TYPES));
        if (baseURI != null && getWriterConfig().get(BasicWriterSettings.BASE_DIRECTIVE)) {
            opts.setBase(baseURI);
        }
        if (mode == JSONLDMode.EXPAND) {
            output = JsonLdProcessor.expand(output, opts);
        }
        // TODO: Implement inframe in JSONLDSettings
        final Object inframe = null;
        if (mode == JSONLDMode.FLATTEN) {
            output = JsonLdProcessor.flatten(output, inframe, opts);
        }
        if (mode == JSONLDMode.COMPACT) {
            final Map<String, Object> ctx = new LinkedHashMap<String, Object>();
            addPrefixes(ctx, model.getNamespaces());
            final Map<String, Object> localCtx = new HashMap<String, Object>();
            localCtx.put("@context", ctx);
            output = JsonLdProcessor.compact(output, localCtx, opts);
        }
        if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
            JsonUtils.writePrettyPrint(writer, output);
        } else {
            JsonUtils.write(writer, output);
        }
    } catch (final JsonLdError e) {
        throw new RDFHandlerException("Could not render JSONLD", e);
    } catch (final JsonGenerationException e) {
        throw new RDFHandlerException("Could not render JSONLD", e);
    } catch (final JsonMappingException e) {
        throw new RDFHandlerException("Could not render JSONLD", e);
    } catch (final IOException e) {
        throw new RDFHandlerException("Could not render JSONLD", e);
    }
}
Also used : JSONLDMode(org.eclipse.rdf4j.rio.helpers.JSONLDMode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) JsonLdError(com.github.jsonldjava.core.JsonLdError) LinkedHashMap(java.util.LinkedHashMap) JsonLdOptions(com.github.jsonldjava.core.JsonLdOptions) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException)

Example 42 with JsonMappingException

use of org.apache.flink.shaded.jackson2.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 43 with JsonMappingException

use of org.apache.flink.shaded.jackson2.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 44 with JsonMappingException

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

the class StatementDeserializer method read.

InputStatement read() {
    switch(state) {
        case BEFORE_OUTER_ARRAY:
            if (!beginsWithCorrectTokens()) {
                return null;
            }
            state = State.IN_BODY;
        case IN_BODY:
            String statement = null;
            Map<String, Object> parameters = null;
            List<Object> resultsDataContents = null;
            boolean includeStats = false;
            JsonToken tok;
            try {
                while ((tok = parser.nextToken()) != null && tok != END_OBJECT) {
                    if (tok == END_ARRAY) {
                        // No more statements
                        state = State.FINISHED;
                        return null;
                    }
                    parser.nextValue();
                    String currentName = parser.getCurrentName();
                    switch(currentName) {
                        case "statement":
                            statement = parser.readValueAs(String.class);
                            break;
                        case "parameters":
                            parameters = readMap();
                            break;
                        case "resultDataContents":
                            resultsDataContents = readArray();
                            break;
                        case "includeStats":
                            includeStats = parser.getBooleanValue();
                            break;
                        default:
                            discardValue();
                    }
                }
                if (statement == null) {
                    throw new InputFormatException("No statement provided.");
                }
                return new InputStatement(statement, parameters == null ? NO_PARAMETERS : parameters, includeStats, ResultDataContent.fromNames(resultsDataContents));
            } catch (JsonParseException e) {
                throw new InputFormatException("Could not parse the incoming JSON", e);
            } catch (JsonMappingException e) {
                throw new InputFormatException("Could not map the incoming JSON", e);
            } catch (IOException e) {
                throw new ConnectionException("An error encountered while reading the inbound entity", e);
            }
        case FINISHED:
            return null;
        default:
            break;
    }
    return null;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) InputFormatException(org.neo4j.server.http.cypher.format.api.InputFormatException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException)

Example 45 with JsonMappingException

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

the class BaseConfigurationFactory method build.

protected T build(JsonNode node, String path) throws IOException, ConfigurationException {
    for (Map.Entry<Object, Object> pref : System.getProperties().entrySet()) {
        final String prefName = (String) pref.getKey();
        if (prefName.startsWith(propertyPrefix)) {
            final String configName = prefName.substring(propertyPrefix.length());
            addOverride(node, configName, System.getProperty(prefName));
        }
    }
    try {
        final T config = mapper.readValue(new TreeTraversingParser(node, mapper), klass);
        validate(path, config);
        return config;
    } catch (UnrecognizedPropertyException e) {
        final List<String> properties = e.getKnownPropertyIds().stream().map(Object::toString).collect(Collectors.toList());
        throw ConfigurationParsingException.builder("Unrecognized field").setFieldPath(e.getPath()).setLocation(e.getLocation()).addSuggestions(properties).setSuggestionBase(e.getPropertyName()).setCause(e).build(path);
    } catch (InvalidFormatException e) {
        final String sourceType = e.getValue().getClass().getSimpleName();
        final String targetType = e.getTargetType().getSimpleName();
        throw ConfigurationParsingException.builder("Incorrect type of value").setDetail("is of type: " + sourceType + ", expected: " + targetType).setLocation(e.getLocation()).setFieldPath(e.getPath()).setCause(e).build(path);
    } catch (JsonMappingException e) {
        throw ConfigurationParsingException.builder("Failed to parse configuration").setDetail(e.getMessage()).setFieldPath(e.getPath()).setLocation(e.getLocation()).setCause(e).build(path);
    }
}
Also used : TreeTraversingParser(com.fasterxml.jackson.databind.node.TreeTraversingParser) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UnrecognizedPropertyException(com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) List(java.util.List) Map(java.util.Map) InvalidFormatException(com.fasterxml.jackson.databind.exc.InvalidFormatException)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)185 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)93 IOException (java.io.IOException)80 JsonParseException (com.fasterxml.jackson.core.JsonParseException)57 Test (org.junit.Test)45 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)33 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)24 ArrayList (java.util.ArrayList)16 Map (java.util.Map)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 File (java.io.File)15 HashMap (java.util.HashMap)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 InputStream (java.io.InputStream)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 List (java.util.List)8 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 Test (org.junit.jupiter.api.Test)6