Search in sources :

Example 6 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.

the class NumberCoercionTest method testToLongFailing.

@SuppressWarnings("resource")
public void testToLongFailing() throws Exception {
    for (int mode : ALL_STREAMING_MODES) {
        JsonParser p;
        // BigInteger -> error
        BigInteger big = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.TEN);
        p = createParser(mode, String.valueOf(big));
        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
        assertEquals(NumberType.BIG_INTEGER, p.getNumberType());
        assertEquals(big, p.getBigIntegerValue());
        assertEquals(big, p.getNumberValue());
        try {
            p.getLongValue();
            fail("Should not pass");
        } catch (JsonParseException e) {
            verifyException(e, "out of range of long");
        }
        BigInteger small = BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.TEN);
        p = createParser(mode, String.valueOf(small));
        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
        assertEquals(small, p.getBigIntegerValue());
        try {
            p.getLongValue();
            fail("Should not pass");
        } catch (JsonParseException e) {
            verifyException(e, "out of range of long");
        }
    }
}
Also used : BigInteger(java.math.BigInteger) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 7 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project asterixdb by apache.

the class QueryServiceServlet method getRequestParameters.

private RequestParameters getRequestParameters(IServletRequest request) throws IOException {
    final String contentTypeParam = request.getHttpRequest().headers().get(HttpHeaderNames.CONTENT_TYPE);
    int sep = contentTypeParam.indexOf(';');
    final String contentType = sep < 0 ? contentTypeParam.trim() : contentTypeParam.substring(0, sep).trim();
    RequestParameters param = new RequestParameters();
    param.host = host(request);
    param.path = servletPath(request);
    if (HttpUtil.ContentType.APPLICATION_JSON.equals(contentType)) {
        try {
            JsonNode jsonRequest = new ObjectMapper().readTree(HttpUtil.getRequestBody(request));
            param.statement = jsonRequest.get(Parameter.STATEMENT.str()).asText();
            param.format = toLower(getOptText(jsonRequest, Parameter.FORMAT.str()));
            param.pretty = getOptBoolean(jsonRequest, Parameter.PRETTY.str(), false);
            param.mode = toLower(getOptText(jsonRequest, Parameter.MODE.str()));
            param.clientContextID = getOptText(jsonRequest, Parameter.CLIENT_ID.str());
        } catch (JsonParseException | JsonMappingException e) {
            // if the JSON parsing fails, the statement is empty and we get an empty statement error
            GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
    } else {
        param.statement = request.getParameter(Parameter.STATEMENT.str());
        if (param.statement == null) {
            param.statement = HttpUtil.getRequestBody(request);
        }
        param.format = toLower(request.getParameter(Parameter.FORMAT.str()));
        param.pretty = Boolean.parseBoolean(request.getParameter(Parameter.PRETTY.str()));
        param.mode = toLower(request.getParameter(Parameter.MODE.str()));
        param.clientContextID = request.getParameter(Parameter.CLIENT_ID.str());
    }
    return param;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project BIMserver by opensourceBIM.

the class JsonQueryObjectModelConverter method getDefineFromFile.

// TODO thread safety and cache invalidation on file updates
public Include getDefineFromFile(String includeName) throws QueryException {
    Include include = CACHED_DEFINES.get(includeName);
    if (include != null) {
        return include;
    }
    String namespaceString = includeName.substring(0, includeName.indexOf(":"));
    String singleIncludeName = includeName.substring(includeName.indexOf(":") + 1);
    URL resource;
    try {
        resource = getClass().getClassLoader().loadClass("org.bimserver.database.queries.StartFrame").getResource("json/" + namespaceString + ".json");
        if (resource == null) {
            throw new QueryException("Could not find '" + namespaceString + "' namespace in predefined queries");
        }
    } catch (ClassNotFoundException e1) {
        throw new QueryException("Could not find '" + namespaceString + "' namespace in predefined queries");
    }
    OBJECT_MAPPER.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    try {
        ObjectNode predefinedQuery = OBJECT_MAPPER.readValue(resource, ObjectNode.class);
        JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
        Query query = converter.parseJson(namespaceString, predefinedQuery);
        Include define = query.getDefine(singleIncludeName);
        if (define == null) {
            throw new QueryException("Could not find '" + singleIncludeName + "' in defines in namespace " + query.getName());
        }
        CACHED_DEFINES.put(includeName, define);
        return define;
    } catch (JsonParseException e) {
        throw new QueryException(e);
    } catch (JsonMappingException e) {
        throw new QueryException(e);
    } catch (IOException e) {
        throw new QueryException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) URL(java.net.URL)

Example 9 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project BIMserver by opensourceBIM.

the class GetNrPrimitivesDatabaseAction method execute.

@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
    if (packageMetaData == null) {
        throw new UserException("Schema not fond");
    }
    try {
        Query query = new Query("test", packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(packageMetaData.getEClassIncludingDependencies("GeometryInfo"), true);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, java.util.Collections.singleton(roid), packageMetaData);
        HashMapVirtualObject next = queryObjectProvider.next();
        long totalPrimitives = 0;
        while (next != null) {
            int nrPrimitives = (int) next.get("primitiveCount");
            totalPrimitives += nrPrimitives;
            next = queryObjectProvider.next();
        }
        return totalPrimitives;
    } catch (QueryException e) {
        e.printStackTrace();
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) UserException(org.bimserver.shared.exceptions.UserException)

Example 10 with JsonParseException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project nifi by apache.

the class SiteToSiteRestApiClient method execute.

private <T> T execute(final HttpGet get, final Class<T> entityClass) throws IOException {
    get.setHeader("Accept", "application/json");
    final String responseMessage = execute(get);
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    try {
        return mapper.readValue(responseMessage, entityClass);
    } catch (JsonParseException e) {
        final String msg = "Failed to parse Json. The specified URL " + baseUrl + " is not a proper remote NiFi endpoint for Site-to-Site communication.";
        logger.warn("{} requestedUrl={}, response={}", msg, get.getURI(), responseMessage);
        throw new IOException(msg, e);
    }
}
Also used : IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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