use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project service-proxy by membrane.
the class EtcdResponse method get.
@SuppressWarnings("unchecked")
public String get(String name) {
JsonParser par = getParser(body);
String result = null;
Map<String, Object> respData = null;
try {
respData = new ObjectMapper().readValue(par, Map.class);
} catch (JsonParseException e) {
} catch (JsonMappingException e) {
} catch (IOException e) {
}
if (respData.containsKey("node")) {
LinkedHashMap<String, Object> nodeJson = (LinkedHashMap<String, Object>) respData.get("node");
if (nodeJson.containsKey(name)) {
result = nodeJson.get(name).toString();
}
}
if (result == null) {
throw new RuntimeException();
}
return result;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project webprotege by protegeproject.
the class FormDataValueDeserializer method deserialize.
@Override
public FormDataValue deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = p.readValueAsTree();
if (node.isTextual()) {
return FormDataPrimitive.get(node.asText());
} else if (node.isNumber()) {
return FormDataPrimitive.get(node.asDouble());
} else if (node.isBoolean()) {
return FormDataPrimitive.get(node.asBoolean());
} else if (node.isObject()) {
if (node.has("iri")) {
if (node.has("type")) {
IRI iri = IRI.create(node.get("iri").asText());
String type = node.get("type").asText();
switch(type) {
case "Class":
return FormDataPrimitive.get(df.getOWLClass(iri));
case "ObjectProperty":
return FormDataPrimitive.get(df.getOWLObjectProperty(iri));
case "DataProperty":
return FormDataPrimitive.get(df.getOWLDataProperty(iri));
case "AnnotationProperty":
return FormDataPrimitive.get(df.getOWLAnnotationProperty(iri));
case "Datatype":
return FormDataPrimitive.get(df.getOWLDatatype(iri));
case "NamedIndividual":
return FormDataPrimitive.get(df.getOWLDatatype(iri));
}
throw new JsonParseException(p, "Unrecognised entity type: " + type);
} else {
return FormDataPrimitive.get(IRI.create(node.get("iri").asText()));
}
} else if (node.has("literal")) {
String literal = node.get("literal").asText();
String lang = node.get("lang").asText("");
return FormDataPrimitive.get(df.getOWLLiteral(literal, lang));
}
}
throw new JsonParseException(p, "Cannot parse node as primitive value");
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project rdf4j by eclipse.
the class JSONLDParser method parse.
@Override
public void parse(final InputStream in, final String baseURI) throws IOException, RDFParseException, RDFHandlerException {
clear();
try {
final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(getRDFHandler(), valueFactory, getParserConfig(), getParseErrorListener(), nodeID -> createNode(nodeID), () -> createNode());
final JsonLdOptions options = new JsonLdOptions(baseURI);
options.useNamespaces = true;
JsonLdProcessor.toRDF(JsonUtils.fromInputStream(in), callback, options);
} catch (final JsonLdError e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final JsonParseException e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final RuntimeException e) {
if (e.getCause() != null && e.getCause() instanceof RDFParseException) {
throw (RDFParseException) e.getCause();
}
throw e;
} finally {
clear();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project rdf4j by eclipse.
the class JSONLDParser method parse.
@Override
public void parse(final Reader reader, final String baseURI) throws IOException, RDFParseException, RDFHandlerException {
clear();
try {
final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(getRDFHandler(), valueFactory, getParserConfig(), getParseErrorListener(), nodeID -> createNode(nodeID), () -> createNode());
final JsonLdOptions options = new JsonLdOptions(baseURI);
options.useNamespaces = true;
JsonLdProcessor.toRDF(JsonUtils.fromReader(reader), callback, options);
} catch (final JsonLdError e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final JsonParseException e) {
throw new RDFParseException("Could not parse JSONLD", e);
} catch (final RuntimeException e) {
if (e.getCause() != null && e.getCause() instanceof RDFParseException) {
throw (RDFParseException) e.getCause();
}
throw e;
} finally {
clear();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException 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) {
}
}
Aggregations