/** * Default method overridden so that we can add location information */ @Override public String getMessage() { String msg = super.getMessage(); if (msg == null) { msg = "N/A"; } JsonLocation loc = getLocation(); String suffix = getMessageSuffix(); // mild optimization, if nothing extra is needed: if (loc != null || suffix != null) { StringBuilder sb = new StringBuilder(100); sb.append(msg); if (suffix != null) { sb.append(suffix); } if (loc != null) { sb.append('\n'); sb.append(" at "); sb.append(loc.toString()); } msg = sb.toString(); } return msg; }
/** * Default method overridden so that we can add location information */ @Override public String getMessage() { String msg = super.getMessage(); if (msg == null) { msg = "N/A"; } JsonLocation loc = getLocation(); String suffix = getMessageSuffix(); // mild optimization, if nothing extra is needed: if (loc != null || suffix != null) { StringBuilder sb = new StringBuilder(100); sb.append(msg); if (suffix != null) { sb.append(suffix); } if (loc != null) { sb.append('\n'); sb.append(" at "); sb.append(loc.toString()); } msg = sb.toString(); } return msg; }
public static JsonReadException fromJackson(JsonProcessingException ex) { String message = ex.getMessage(); // Strip off location. int locPos = message.lastIndexOf(" at [Source"); if (locPos >= 0) { message = message.substring(0, locPos); } return new JsonReadException(message, ex.getLocation()); } }
private static Map<String,Object> readFragment(File file, String ext) throws IOException { ObjectMapper mapper = new ObjectMapper("json".equals(ext) ? new JsonFactory() : new YAMLFactory()); TypeReference<HashMap<String,Object>> typeRef = new TypeReference<HashMap<String,Object>>() {}; try { Map<String, Object> ret = mapper.readValue(file, typeRef); return ret != null ? ret : new HashMap<String, Object>(); } catch (JsonProcessingException e) { throw new JsonMappingException(String.format("[%s] %s", file, e.getMessage()), e.getLocation(), e); } }
public static SwaggerError newJsonError(JsonProcessingException exception) { int line = (exception.getLocation() != null) ? exception.getLocation().getLineNr() : 1; return new SwaggerError(line, IMarker.SEVERITY_ERROR, 0, exception.getMessage()); }
private static StyleConfiguration readConfig(ObjectReader reader, StyleResource config) { try (InputStream is = config.openStream()) { return reader.readValue(is); } catch (JsonProcessingException e) { String message = String.format("Unable to read style configuration %s.\nLocation: line %s, column %s\nDetails: %s", config, e.getLocation().getLineNr(), e.getLocation().getColumnNr(), e.getOriginalMessage()); throw new RuntimeException(message); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Default method overridden so that we can add location information */ @Override public String getMessage() { String msg = super.getMessage(); if (msg == null) { msg = "N/A"; } JsonLocation loc = getLocation(); String suffix = getMessageSuffix(); // mild optimization, if nothing extra is needed: if (loc != null || suffix != null) { StringBuilder sb = new StringBuilder(100); sb.append(msg); if (suffix != null) { sb.append(suffix); } if (loc != null) { sb.append('\n'); sb.append(" at "); sb.append(loc.toString()); } msg = sb.toString(); } return msg; }
private static YamlParserException toErr(String msg, JsonProcessingException jpe) { JsonLocation loc = jpe.getLocation(); String originalMsg = jpe.getOriginalMessage(); return new YamlParserException(msg + " @ " + loc + ". " + originalMsg); } }
/** * Default method overridden so that we can add location information */ @Override public String getMessage() { String msg = super.getMessage(); if (msg == null) { msg = "N/A"; } JsonLocation loc = getLocation(); String suffix = getMessageSuffix(); // mild optimization, if nothing extra is needed: if (loc != null || suffix != null) { StringBuilder sb = new StringBuilder(100); sb.append(msg); if (suffix != null) { sb.append(suffix); } if (loc != null) { sb.append('\n'); sb.append(" at "); sb.append(loc.toString()); } msg = sb.toString(); } return msg; }
/** * Default method overridden so that we can add location information */ @Override public String getMessage() { String msg = super.getMessage(); if (msg == null) { msg = "N/A"; } JsonLocation loc = getLocation(); String suffix = getMessageSuffix(); // mild optimization, if nothing extra is needed: if (loc != null || suffix != null) { StringBuilder sb = new StringBuilder(100); sb.append(msg); if (suffix != null) { sb.append(suffix); } if (loc != null) { sb.append('\n'); sb.append(" at "); sb.append(loc.toString()); } msg = sb.toString(); } return msg; }
/** * Default method overridden so that we can add location information */ @Override public String getMessage() { String msg = super.getMessage(); if (msg == null) { msg = "N/A"; } JsonLocation loc = getLocation(); String suffix = getMessageSuffix(); // mild optimization, if nothing extra is needed: if (loc != null || suffix != null) { StringBuilder sb = new StringBuilder(100); sb.append(msg); if (suffix != null) { sb.append(suffix); } if (loc != null) { sb.append('\n'); sb.append(" at "); sb.append(loc.toString()); } msg = sb.toString(); } return msg; }
/** * Default method overridden so that we can add location information */ @Override public String getMessage() { String msg = super.getMessage(); if (msg == null) { msg = "N/A"; } JsonLocation loc = getLocation(); String suffix = getMessageSuffix(); // mild optimization, if nothing extra is needed: if (loc != null || suffix != null) { StringBuilder sb = new StringBuilder(100); sb.append(msg); if (suffix != null) { sb.append(suffix); } if (loc != null) { sb.append('\n'); sb.append(" at "); sb.append(loc.toString()); } msg = sb.toString(); } return msg; }
/** * {@inheritDoc} */ @Override public <T> T toUnmarshaled( String aHttpBody, Class<T> aType ) throws UnmarshalException { try { if ( aHttpBody == null ) { return null; } else if ( aHttpBody.length() == 0 ) { return aType.getConstructor().newInstance(); } T theFromYaml = _mapper.readValue( aHttpBody, aType ); return theFromYaml; } catch ( JsonMappingException | JsonParseException e ) { throw new UnmarshalException( "A problem occurred unmarshaling the HTTP body \"" + aHttpBody + "\" to type <" + aType.getName() + "> at column <" + e.getLocation().getColumnNr() + ">.", e ); } catch ( Exception e ) { throw new UnmarshalException( "A problem occurred unmarshaling the HTTP body \"" + aHttpBody + "\" to type <" + aType.getName() + ">.", e ); } }
/** * {@inheritDoc} */ @Override public <T> T toUnmarshaled( String aHttpBody, Class<T> aType ) throws UnmarshalException { try { if ( aHttpBody == null ) { return null; } else if ( aHttpBody.length() == 0 ) { return aType.getConstructor().newInstance(); } T theFromJson = _mapper.readValue( aHttpBody, aType ); return theFromJson; } catch ( JsonMappingException | JsonParseException e ) { throw new UnmarshalException( "A problem occurred unmarshaling the HTTP body \"" + aHttpBody + "\" to type <" + aType.getName() + "> at column <" + e.getLocation().getColumnNr() + ">.", e ); } catch ( Exception e ) { throw new UnmarshalException( "A problem occurred unmarshaling the HTTP body \"" + aHttpBody + "\" to type <" + aType.getName() + ">.", e ); } }
/** * {@inheritDoc} */ @Override public Properties loadFrom( InputStream aInputStream, char... aDelimiters ) throws IOException, ParseException { ObjectMapper theMapper = new ObjectMapper( new YAMLFactory() ); // theMapper.enable( SerializationFeature.WRITE_ENUMS_USING_TO_STRING ); // theMapper.enable( DeserializationFeature.READ_ENUMS_USING_TO_STRING ); try { Map<String, String> theProperties = theMapper.readValue( aInputStream, new TypeReference<Map<?, ?>>() {} ); PropertiesBuilder theResult = new PropertiesBuilderImpl( theProperties ); postProcessAttributes( theResult ); putAll( (Properties) theResult ); return theResult; } catch ( JsonMappingException | JsonParseException e ) { throw new ParseException( e.getMessage(), e.getLocation().getColumnNr() ); } }
/** * {@inheritDoc} */ @Override public Properties loadFrom( InputStream aInputStream, char... aDelimiters ) throws IOException, ParseException { ObjectMapper theMapper = new ObjectMapper(); // theMapper.enable( SerializationFeature.WRITE_ENUMS_USING_TO_STRING ); // theMapper.enable( DeserializationFeature.READ_ENUMS_USING_TO_STRING ); try { Map<String, String> theProperties = theMapper.readValue( aInputStream, new TypeReference<Map<?, ?>>() {} ); PropertiesBuilder theResult = new PropertiesBuilderImpl( theProperties ); postProcessAttributes( theResult ); insert( theResult ); return theResult; } catch ( JsonMappingException | JsonParseException e ) { throw new ParseException( e.getMessage(), e.getLocation().getColumnNr() ); } }
/** * {@inheritDoc} */ @Override public Properties loadFrom( InputStream aInputStream, char... aDelimiters ) throws IOException, ParseException { ObjectMapper theMapper = new ObjectMapper(); // theMapper.enable( SerializationFeature.WRITE_ENUMS_USING_TO_STRING ); // theMapper.enable( DeserializationFeature.READ_ENUMS_USING_TO_STRING ); // As of XML "array" support |--> JSONObject theJsonObj = XML.toJSONObject( toString( aInputStream ) ); String theJson = theJsonObj.toString( 4 ); // As of XML "array" support <--| try { Map<String, String> theProperties = theMapper.readValue( theJson, new TypeReference<Map<?, ?>>() {} ); PropertiesBuilder theResult = new PropertiesBuilderImpl( theProperties ); // Auto-detect whether we have a root element |--> Set<String> theDirs = theResult.dirs(); if ( theDirs.size() == 1 ) { String theDir = theDirs.iterator().next(); theResult = new PropertiesBuilderImpl( theResult.retrieveFrom( theDir ) ); } // Auto-detect whether we have a root element <--| postProcessAttributes( theResult ); putAll( (Properties) theResult ); return theResult; } catch ( JsonMappingException | JsonParseException e ) { throw new ParseException( e.getMessage(), e.getLocation().getColumnNr() ); } }
@Override public void read(Reader reader, String baseURI, ContentType ct, StreamRDF output, Context context) { try { Object jsonObject = JsonUtils.fromReader(reader) ; read$(jsonObject, baseURI, ct, output, context) ; } catch (JsonProcessingException ex) { // includes JsonParseException // The Jackson JSON parser, or addition JSON-level check, throws up something. JsonLocation loc = ex.getLocation() ; errorHandler.error(ex.getOriginalMessage(), loc.getLineNr(), loc.getColumnNr()); throw new RiotException(ex.getOriginalMessage()) ; } catch (IOException e) { errorHandler.error(e.getMessage(), -1, -1); IO.exception(e) ; } }
JsonLocation loc = ex.getLocation() ; errorHandler.error(ex.getOriginalMessage(), loc.getLineNr(), loc.getColumnNr()); throw new RiotException(ex.getOriginalMessage()) ;
JsonLocation jsonLocation = ex.getLocation(); if (jsonLocation != null) { lineNumber = jsonLocation.getLineNr();