List of usage examples for com.fasterxml.jackson.databind JsonMappingException getOriginalMessage
public String getOriginalMessage()
From source file:com.addthis.codec.jackson.Jackson.java
public static String rootMessage(JsonMappingException ex) { String rootMessage = ex.getOriginalMessage(); if (ex instanceof PropertyBindingException) { String suffix = ((PropertyBindingException) ex).getMessageSuffix(); if (rootMessage == null) { return suffix; } else if (suffix != null) { return rootMessage + suffix; }/*from w w w . j a v a 2 s . c om*/ } return rootMessage; }
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. c o m * @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:org.sherlok.FileBased.java
/** * Read a JSON-serialized object from file and parse it back to an object. * Performs extensive error-catching to provide useful information in case * of error./*from w ww .jav a 2s .co m*/ * * @param f * the file to read * @param clazz * the class to cast this object into * @return the parsed object * @throws SherlokException * if the object cannot be found or parsed */ public static <T> T read(File f, Class<T> clazz) throws SherlokException { try { return MAPPER.readValue(new FileInputStream(f), clazz); } catch (FileNotFoundException io) { throw new SherlokException() .setMessage(clazz.getSimpleName().replaceAll("Def$", "") + " does not exist.") .setObject(f.getName()).setDetails(io.toString()); } catch (UnrecognizedPropertyException upe) { throw new SherlokException().setMessage("Unrecognized field \"" + upe.getPropertyName() + "\"") .setObject(clazz.getSimpleName().replaceAll("Def$", "") + " " + f.getName()) .setDetails(upe.getMessageSuffix()); } catch (JsonMappingException jme) { StringBuilder sb = new StringBuilder(); sb.append("cannot read "); jme.getPathReference(sb); sb.append(" in '" + f.getName() + "': "); sb.append(" " + jme.getOriginalMessage()); throw new SherlokException() .setMessage(sb.toString().replaceAll("org\\.sherlok\\.mappings\\.\\w+Def\\[", "[")); } catch (JsonParseException jpe) { throw new SherlokException().setMessage("Could not parse JSON object of type " + clazz.getSimpleName()) .setObject(f.getName().replaceAll("Def$", "")).setDetails(jpe.getMessage()); } catch (Exception e) { throw new SherlokException().setMessage(e.getMessage()).setObject(f.getName().replaceAll("Def$", "")) .setDetails(e.getStackTrace()); } }