Search in sources :

Example 6 with JsonParseException

use of 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 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 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 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 com.fasterxml.jackson.core.JsonParseException in project uPortal by Jasig.

the class AnalyticsIncorporationComponent method serializePortletRenderExecutionEvents.

protected String serializePortletRenderExecutionEvents(final Set<PortalEvent> portalEvents) {
    // Filter to include just portlet render events
    final Map<String, PortletRenderExecutionEvent> renderEvents = new HashMap<>();
    for (final PortalEvent portalEvent : portalEvents) {
        if (portalEvent instanceof PortletRenderExecutionEvent) {
            final PortletRenderExecutionEvent portletRenderEvent = (PortletRenderExecutionEvent) portalEvent;
            // Don't write out info for minimized portlets
            if (!WindowState.MINIMIZED.equals(portletRenderEvent.getWindowState())) {
                final IPortletWindowId portletWindowId = portletRenderEvent.getPortletWindowId();
                final String eventKey = portletWindowId != null ? portletWindowId.getStringId() : portletRenderEvent.getFname();
                renderEvents.put(eventKey, portletRenderEvent);
            }
        }
    }
    try {
        return portletEventWriter.writeValueAsString(renderEvents);
    } catch (JsonParseException e) {
        logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
    } catch (JsonMappingException e) {
        logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
    } catch (IOException e) {
        logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
    }
    return "{}";
}
Also used : PortalEvent(org.apereo.portal.events.PortalEvent) HashMap(java.util.HashMap) PortletRenderExecutionEvent(org.apereo.portal.events.PortletRenderExecutionEvent) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)120 IOException (java.io.IOException)59 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)53 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 JsonParser (com.fasterxml.jackson.core.JsonParser)21 Map (java.util.Map)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 InputStream (java.io.InputStream)12 HashMap (java.util.HashMap)12 JsonToken (com.fasterxml.jackson.core.JsonToken)11 JsonFactory (com.fasterxml.jackson.core.JsonFactory)9 File (java.io.File)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)4