Search in sources :

Example 41 with JsonParseException

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;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) LinkedHashMap(java.util.LinkedHashMap)

Example 42 with JsonParseException

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");
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 43 with JsonParseException

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();
    }
}
Also used : JsonLdOptions(com.github.jsonldjava.core.JsonLdOptions) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonLdError(com.github.jsonldjava.core.JsonLdError) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 44 with JsonParseException

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();
    }
}
Also used : JsonLdOptions(com.github.jsonldjava.core.JsonLdOptions) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonLdError(com.github.jsonldjava.core.JsonLdError) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 45 with JsonParseException

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

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)145 IOException (java.io.IOException)75 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)58 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 JsonParser (com.fasterxml.jackson.core.JsonParser)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 Map (java.util.Map)19 JsonToken (com.fasterxml.jackson.core.JsonToken)15 InputStream (java.io.InputStream)15 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)12 File (java.io.File)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonFactory (com.fasterxml.jackson.core.JsonFactory)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5