Search in sources :

Example 86 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project cas by apereo.

the class X509CertificateCredentialJsonSerializer method serializeWithType.

@Override
public void serializeWithType(final X509CertificateCredential value, final JsonGenerator generator, final SerializerProvider serializers, final TypeSerializer typeSer) throws IOException {
    try {
        typeSer.writeTypePrefixForObject(value, generator);
        serialize(value, generator, serializers);
        typeSer.writeTypeSuffixForObject(value, generator);
    } catch (final Exception e) {
        throw new JsonMappingException("Unable to serialize X509 certificate", e);
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 87 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project uPortal by Jasig.

the class AnalyticsIncorporationComponent method serializePageData.

protected String serializePageData(HttpServletRequest request, long startTime) {
    final Map<String, Object> pageData = new HashMap<>();
    pageData.put("executionTimeNano", System.nanoTime() - startTime);
    final IPortalRequestInfo portalRequestInfo = urlSyntaxProvider.getPortalRequestInfo(request);
    pageData.put("urlState", portalRequestInfo.getUrlState());
    final String targetedLayoutNodeId = portalRequestInfo.getTargetedLayoutNodeId();
    if (targetedLayoutNodeId != null) {
        final AggregatedTabMapping mappedTabForLayoutId = aggregatedTabLookupDao.getMappedTabForLayoutId(targetedLayoutNodeId);
        pageData.put("tab", mappedTabForLayoutId);
    }
    try {
        return mapper.writeValueAsString(pageData);
    } catch (JsonParseException e) {
        logger.warn("Failed to convert this request's page data to JSON, no page level analytics will be included", e);
    } catch (JsonMappingException e) {
        logger.warn("Failed to convert this request's page data to JSON, no page level analytics will be included", e);
    } catch (IOException e) {
        logger.warn("Failed to convert this request's page data to JSON, no page level analytics will be included", e);
    }
    return "{}";
}
Also used : IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) HashMap(java.util.HashMap) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) AggregatedTabMapping(org.apereo.portal.events.aggr.tabs.AggregatedTabMapping)

Example 88 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project dhis2-core by dhis2.

the class GeoUtils method parseCoordinates.

public static Coordinates parseCoordinates(String coordinatesString, CoordinateOrder from) {
    Coordinates coordinates = new Coordinates();
    try {
        List<?> list = new ObjectMapper().readValue(coordinatesString, List.class);
        if (!list.isEmpty() && from == CoordinateOrder.COORDINATE_LATLNG) {
            coordinates.lat = convertToDouble(list.get(0));
            coordinates.lng = convertToDouble(list.get(1));
        } else if (!list.isEmpty() && from == CoordinateOrder.COORDINATE_LNGLAT) {
            coordinates.lat = convertToDouble(list.get(1));
            coordinates.lng = convertToDouble(list.get(0));
        }
    } catch (JsonMappingException ignored) {
    } catch (JsonParseException ignored) {
    } catch (IOException ignored) {
    }
    return coordinates;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 89 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project dhis2-core by dhis2.

the class DefaultAppManager method installApp.

@Override
public AppStatus installApp(File file, String fileName) {
    try {
        // -----------------------------------------------------------------
        // Parse ZIP file and it's manifest.webapp file.
        // -----------------------------------------------------------------
        ZipFile zip = new ZipFile(file);
        ZipEntry entry = zip.getEntry(MANIFEST_FILENAME);
        InputStream inputStream = zip.getInputStream(entry);
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        App app = mapper.readValue(inputStream, App.class);
        // -----------------------------------------------------------------
        // Check for namespace and if it's already taken by another app
        // -----------------------------------------------------------------
        String namespace = app.getActivities().getDhis().getNamespace();
        if (namespace != null && (this.appNamespaces.containsKey(namespace) && !app.equals(appNamespaces.get(namespace)))) {
            zip.close();
            return AppStatus.NAMESPACE_TAKEN;
        }
        // -----------------------------------------------------------------
        // Delete if app is already installed, assuming app update so no 
        // data is deleted
        // -----------------------------------------------------------------
        deleteApp(app.getName(), false);
        // -----------------------------------------------------------------
        // Unzip the app
        // -----------------------------------------------------------------
        log.info("Installing app, namespace: " + namespace);
        String dest = getAppFolderPath() + File.separator + fileName.substring(0, fileName.lastIndexOf('.'));
        Unzip unzip = new Unzip();
        unzip.setSrc(file);
        unzip.setDest(new File(dest));
        unzip.execute();
        log.info("Installed app: " + app);
        // -----------------------------------------------------------------
        // Installation complete. Closing zip, reloading apps and return OK
        // -----------------------------------------------------------------
        zip.close();
        reloadApps();
        return AppStatus.OK;
    } catch (ZipException e) {
        return AppStatus.INVALID_ZIP_FORMAT;
    } catch (JsonParseException e) {
        return AppStatus.INVALID_MANIFEST_JSON;
    } catch (JsonMappingException e) {
        return AppStatus.INVALID_MANIFEST_JSON;
    } catch (IOException e) {
        return AppStatus.INSTALLATION_FAILED;
    }
}
Also used : ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Unzip(org.apache.ant.compress.taskdefs.Unzip) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ZipFile(java.util.zip.ZipFile) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 90 with JsonMappingException

use of com.fasterxml.jackson.databind.JsonMappingException in project blueocean-plugin by jenkinsci.

the class HttpRequest method to.

public <T> T to(Class<T> type) throws IOException {
    HttpURLConnection connection = connect();
    if (methodNeedsBody()) {
        if (body == null) {
            GithubScm.om.writeValue(connection.getOutputStream(), Collections.emptyMap());
        } else {
            GithubScm.om.writeValue(connection.getOutputStream(), body);
        }
    }
    InputStreamReader r = null;
    try {
        int status = connection.getResponseCode();
        if (status == 304) {
            return null;
        }
        if (status == 204 && type != null && type.isArray()) {
            return type.cast(Array.newInstance(type.getComponentType(), 0));
        }
        if (status == 401 || status == 403) {
            throw new ServiceException.ForbiddenException("Invalid accessToken");
        }
        if (status == 404) {
            throw new ServiceException.NotFoundException("Not Found. Remote server sent code " + getErrorResponse(connection));
        }
        if (status > 399) {
            throw new ServiceException.BadRequestException(String.format("%s %s returned error: %s. Error message: %s.", method, url, status, getErrorResponse(connection)));
        }
        if (!method.equals("HEAD")) {
            r = new InputStreamReader(wrapStream(connection.getInputStream(), connection.getContentEncoding()), "UTF-8");
            String data = IOUtils.toString(r);
            if (type != null) {
                try {
                    return GithubScm.om.readValue(data, type);
                } catch (JsonMappingException e) {
                    throw new IOException("Failed to deserialize: " + e.getMessage() + "\n" + data, e);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(r);
    }
    return null;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)140 IOException (java.io.IOException)68 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 JsonParseException (com.fasterxml.jackson.core.JsonParseException)52 Test (org.junit.Test)31 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)19 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)14 Map (java.util.Map)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 File (java.io.File)9 InputStream (java.io.InputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 List (java.util.List)7 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 Response (javax.ws.rs.core.Response)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)5