Example usage for com.fasterxml.jackson.core JsonProcessingException getMessage

List of usage examples for com.fasterxml.jackson.core JsonProcessingException getMessage

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonProcessingException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Document

Default method overridden so that we can add location information

Usage

From source file:io.qdb.server.controller.JsonService.java

/**
 * Converts content to an instance of a particular type. Throws IllegalArgumentException if JSON is invalid.
 *//*from w  w  w  . j  ava 2  s .c o m*/
public <T> T fromJson(InputStream ins, Class<T> klass) throws IOException {
    try {
        return mapper.readValue(ins, klass);
    } catch (JsonProcessingException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}

From source file:com.liferay.nativity.control.win.WindowsNativityControlImpl.java

@Override
public void setFilterFolders(String[] folders) {
    try {/*from w  ww  . ja  va2s.com*/
        String foldersJson = _objectMapper.writeValueAsString(folders);

        RegistryUtil.writeRegistry(Constants.NATIVITY_REGISTRY_KEY, Constants.FILTER_FOLDERS_REGISTRY_NAME,
                foldersJson);
    } catch (JsonProcessingException jpe) {
        _logger.error(jpe.getMessage(), jpe);
    }

    for (String folder : folders) {
        WindowsNativityUtil.refreshExplorer(folder);
    }
}

From source file:com.unboundid.scim2.server.TestSingletonResourceEndpoint.java

/**
 * Test SCIM modify./*from  w  w  w . java 2  s  .  c o  m*/
 *
 * @param id The ID of the resource to modify.
 * @param patchRequest The patch request.
 * @param uriInfo The UriInfo.
 * @return The result.
 * @throws ScimException if an error occurs.
 */
@Path("{id}")
@PATCH
@Consumes({ MEDIA_TYPE_SCIM, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM, MediaType.APPLICATION_JSON })
public ScimResource modify(@PathParam("id") final String id, final PatchRequest patchRequest,
        @Context final UriInfo uriInfo) throws ScimException {
    UserResource found = users.get(id);
    if (found == null) {
        throw new ResourceNotFoundException("No resource with ID " + id);
    }
    ObjectNode node = JsonUtils.valueToNode(found);
    for (PatchOperation operation : patchRequest) {
        operation.apply(node);
    }
    UserResource patchedFound = null;
    try {
        patchedFound = JsonUtils.getObjectReader().treeToValue(node, UserResource.class);
    } catch (JsonProcessingException e) {
        throw new ServerErrorException(e.getMessage(), null, e);
    }
    users.put(id, patchedFound);
    ResourcePreparer<UserResource> resourcePreparer = new ResourcePreparer<UserResource>(
            RESOURCE_TYPE_DEFINITION, uriInfo);
    return resourcePreparer.trimModifiedResource(patchedFound, patchRequest);
}

From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.MeterResource.java

/**
 * Returns the last persisted list of meters
 * <p/>/*from  w  ww.j  a va2  s  .  com*/
 * Pseudo Code<br>
 * 1. Receive the request for the list of meters<br>
 * 2. Query the DB to get the list<br>
 * 3. Return the list of meters
 *
 * @return Representation A JSON response containing the list of meters
 */
@Get
public Representation getMeterList() {
    counter.increment(endpoint);

    JsonRepresentation responseJson = null;
    TSDBData responseObj;
    ObjectMapper mapper = new ObjectMapper();
    TSDBResource tsdbResource = new TSDBResource();
    responseObj = tsdbResource.getMeterList();

    try {
        String jsonStr = mapper.writeValueAsString(responseObj);
        responseJson = new JsonRepresentation(jsonStr);
    } catch (JsonProcessingException e) {
        logger.error("Could not parse JSON when getting meterList: " + e.getMessage());
        e.printStackTrace();
    }

    return responseJson;
}

From source file:org.ccntgrid.extend.spring.http.converter.json.MappingJackson2HttpMessageConverter.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory()
            .createJsonGenerator(outputMessage.getBody(), encoding);
    try {// w  w w. jav  a 2s .c om
        if (this.prefixJson) {
            jsonGenerator.writeRaw("{} && ");
        }
        this.objectMapper.writeValue(jsonGenerator, object);
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

From source file:org.wikidata.wdtk.dumpfiles.JsonDumpFileProcessor.java

/**
 * Reports the error of a JSON processing exception that was caught when
 * trying to read an entity./*from   ww w. ja  v a  2s  .  c  o m*/
 *
 * @param exception
 *            the exception to log
 */
private void logJsonProcessingException(JsonProcessingException exception) {
    JsonDumpFileProcessor.logger.error("Error when reading JSON for entity: " + exception.getMessage());
}

From source file:com.blockwithme.lessobjects.util.JSONParser.java

/**
 * To xml string./*from   w  w  w.j  a  va  2s  .c om*/
 *
 * @return the string
 */
@SuppressWarnings("null")
public String toXMLString() {

    if (xmlString == null) {
        if (!fromSchema) {
            try {
                final XmlMapper mapper = new XmlMapper();
                xmlString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
            } catch (final JsonProcessingException jpe) {
                throw new IllegalStateException(jpe.getMessage(), jpe);
            }
        } else {
            try {
                if (format == SchemaFormat.JSON) {
                    if (jsonString == null) {
                        jsonString = jsonOrXMLString;
                    }
                    schema = getBinding();
                    xmlString = new XmlMapper().writerWithDefaultPrettyPrinter().writeValueAsString(schema);
                } else {
                    xmlString = jsonOrXMLString;
                }
            } catch (final IOException e) {
                throw new IllegalStateException(e.getMessage(), e);
            }
        }
    }
    return xmlString;
}

From source file:org.oncoblocks.centromere.web.util.FilteringJackson2HttpMessageConverter.java

@Override
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    ObjectMapper objectMapper = getObjectMapper();
    JsonGenerator jsonGenerator = objectMapper.getFactory().createGenerator(outputMessage.getBody());

    try {//  w  ww .  j  ava  2 s .  com

        if (this.prefixJson) {
            jsonGenerator.writeRaw(")]}', ");
        }

        if (object instanceof ResponseEnvelope) {

            ResponseEnvelope envelope = (ResponseEnvelope) object;
            Object entity = envelope.getEntity();
            Set<String> fieldSet = envelope.getFieldSet();
            Set<String> exclude = envelope.getExclude();
            FilterProvider filters = null;

            if (fieldSet != null && !fieldSet.isEmpty()) {
                if (entity instanceof ResourceSupport) {
                    fieldSet.add("content"); // Don't filter out the wrapped content.
                }
                filters = new SimpleFilterProvider()
                        .addFilter("fieldFilter", SimpleBeanPropertyFilter.filterOutAllExcept(fieldSet))
                        .setFailOnUnknownId(false);
            } else if (exclude != null && !exclude.isEmpty()) {
                filters = new SimpleFilterProvider()
                        .addFilter("fieldFilter", SimpleBeanPropertyFilter.serializeAllExcept(exclude))
                        .setFailOnUnknownId(false);
            } else {
                filters = new SimpleFilterProvider()
                        .addFilter("fieldFilter", SimpleBeanPropertyFilter.serializeAllExcept())
                        .setFailOnUnknownId(false);
            }

            objectMapper.setFilterProvider(filters);
            objectMapper.writeValue(jsonGenerator, entity);

        } else if (object == null) {
            jsonGenerator.writeNull();
        } else {
            FilterProvider filters = new SimpleFilterProvider().setFailOnUnknownId(false);
            objectMapper.setFilterProvider(filters);
            objectMapper.writeValue(jsonGenerator, object);
        }

    } catch (JsonProcessingException e) {
        e.printStackTrace();
        throw new HttpMessageNotWritableException("Could not write JSON: " + e.getMessage());
    }

}

From source file:eu.supersede.fe.application.ApplicationUtil.java

/**
 * Add an application with the given name, labels and home page.
 * @param applicationName//w w w  .ja v  a 2  s  .  c  o  m
 * @param applicationLabels
 * @param homePage
 */
public void addApplication(String applicationName, Map<String, String> applicationLabels, String homePage) {
    Application app = new Application(applicationName, applicationLabels, homePage);

    try {
        template.opsForHash().put(APP_KEY, app.getId(), mapper.writeValueAsString(app));
    } catch (JsonProcessingException e) {
        log.debug(e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.blockwithme.lessobjects.util.JSONParser.java

/**
 * To json string.//from   w ww .j  a  va 2s.  c o  m
 *
 * @return the string
 */
@SuppressWarnings("null")
public String toJSONString() {

    if (jsonString == null) {
        if (fromSchema) {
            try {
                final ObjectWriter writer = initMapper();
                jsonString = writer.writeValueAsString(schema);
            } catch (final JsonProcessingException jpe) {
                throw new IllegalStateException(jpe.getMessage(), jpe);
            }
        } else {
            try {
                if (format == SchemaFormat.JSON) {
                    jsonString = jsonOrXMLString;
                } else {
                    if (xmlString == null) {
                        xmlString = jsonOrXMLString;
                    }
                    final XmlMapper xmlMapper = new XmlMapper();
                    schema = xmlMapper.readValue(jsonOrXMLString, StructSchema.class);
                    final ObjectMapper jsonMapper = new ObjectMapper();
                    jsonString = jsonMapper.writeValueAsString(schema);
                }
            } catch (final IOException e) {
                throw new IllegalStateException(e.getMessage(), e);
            }
        }
    }
    return jsonString;
}