Example usage for com.fasterxml.jackson.databind JsonMappingException getMessage

List of usage examples for com.fasterxml.jackson.databind JsonMappingException getMessage

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonMappingException getMessage.

Prototype

public String getMessage() 

Source Link

Usage

From source file:com.github.fge.jsonschema.core.load.URIManager.java

/**
 * Get the content at a given URI as a {@link JsonNode}
 *
 * @param uri the URI//from  w w  w  .  j a v a 2 s  .com
 * @return the content
 * @throws NullPointerException provided URI is null
 * @throws ProcessingException scheme is not registered, failed to get
 * content, or content is not JSON
 */
public JsonNode getContent(final URI uri) throws ProcessingException {
    BUNDLE.checkNotNull(uri, "jsonRef.nullURI");

    if (!uri.isAbsolute())
        throw new ProcessingException(new ProcessingMessage()
                .setMessage(BUNDLE.getMessage("refProcessing.uriNotAbsolute")).put("uri", uri));

    final String scheme = uri.getScheme();

    final URIDownloader downloader = downloaders.get(scheme);

    if (downloader == null)
        throw new ProcessingException(
                new ProcessingMessage().setMessage(BUNDLE.getMessage("refProcessing.unhandledScheme"))
                        .putArgument("scheme", scheme).putArgument("uri", uri));

    final Closer closer = Closer.create();
    final InputStream in;

    try {
        in = closer.register(downloader.fetch(uri));
        return reader.fromInputStream(in);
    } catch (JsonMappingException e) {
        throw new ProcessingException(
                new ProcessingMessage().setMessage(e.getOriginalMessage()).put("uri", uri));
    } catch (JsonParseException e) {
        throw new ProcessingException(
                new ProcessingMessage().setMessage(BUNDLE.getMessage("uriManager.uriNotJson"))
                        .putArgument("uri", uri).put("parsingMessage", e.getOriginalMessage()));
    } catch (IOException e) {
        throw new ProcessingException(
                new ProcessingMessage().setMessage(BUNDLE.getMessage("uriManager.uriIOError"))
                        .putArgument("uri", uri).put("exceptionMessage", e.getMessage()));
    } finally {
        try {
            closer.close();
        } catch (IOException ignored) {
            throw new IllegalStateException();
        }
    }
}

From source file:jp.furplag.util.JSONifierTest.java

@Test
public final void testStringify() throws JsonGenerationException, JsonMappingException, IOException {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    assertEquals("null", "null", stringify(null));
    assertEquals("[null]", "[null]", stringify(new Object[] { null }));
    assertEquals("null...", "[null,null,null]", stringify(new Object[] { null, null, null }));
    assertEquals("empty : Object", "{}", stringify(map));
    assertEquals("empty : Array", "[]", stringify(map.keySet().toArray(new String[] {})));
    assertEquals("empty : Collenction", "[]", stringify(map.entrySet()));
    assertEquals("wrong usage", "\"{\\\"1\\\":2,\\\"a\\\":\\\"b\\\",\\\"Key\\\":null}\"",
            stringify("{\"1\":2,\"a\":\"b\",\"Key\":null}"));

    map.put("1", 2);
    map.put("a", "b");
    map.put("Key", null);
    assertEquals("Array", "[\"1\",\"a\",\"Key\"]", stringify(map.keySet().toArray(new String[] {})));
    assertEquals("Collenction Map", "{\"1\":2,\"a\":\"b\",\"Key\":null}", stringify(map));
    assertEquals("Collenction Set", "[{\"1\":2},{\"a\":\"b\"},{\"Key\":null}]", stringify(map.entrySet()));
    try {/*from  w  w  w  .j a  v a  2s .c  om*/
        assertNotNull("failure : No Serializer", stringify(new EntityOfTest(1, "john")));
        fail("no serializer test failed.");
    } catch (JsonMappingException e) {
    }
    try {
        assertNotNull("failure : No getter", stringify(new EntityOfTestSerializable(1, "john")));
        fail("No getter test failed.");
    } catch (JsonMappingException e) {
    }
    map.put("Entity1", new EntityOfTestJSONifiable(1, "Lorem"));
    map.put("Entity2", new EntityOfTestJSONifiable(2, "ipsum"));
    map.put("Entity3", new EntityOfTestJSONifiable(3, "dolor"));

    try {
        assertEquals("Object",
                "{\"1\":2,\"a\":\"b\",\"Key\":null,\"Entity1\":{\"id\":1,\"name\":\"Lorem\"},\"Entity2\":{\"id\":2,\"name\":\"ipsum\"},\"Entity3\":{\"id\":3,\"name\":\"dolor\"}}",
                stringify(map));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}