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