// Update and return given train line with the Jackson parser // AG public static <T> TrainLine updateLine(T address, TrainLine line) { try { Object trainData = new Object(); if (address instanceof URL) { // Get train data from web trainData = mapper.readValue((URL) address, Object.class); } else if (address instanceof File) { // Get train data locally trainData = mapper.readValue((File) address, Object.class); } // System.out.println(trainData.toString()); // Go inside the wrapper Object tripListObj = getFromMap(trainData, TRIP_LIST_KEY); line = new TrainLine(tripListObj); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return line; }
/** * Helper method for constructing exception to indicate that given type id (parsed from JSON) * could not be converted to a Java type. */ public JsonMappingException unknownTypeException(JavaType type, String id) { return JsonMappingException.from( _parser, "Could not resolve type id '" + id + "' into a subtype of " + type); }
public JsonMappingException endOfInputException(Class<?> instClass) { return JsonMappingException.from( _parser, "Unexpected end-of-input when trying to deserialize a " + instClass.getName()); }
public JsonMappingException instantiationException(Class<?> instClass, String msg) { return JsonMappingException.from( _parser, "Can not construct instance of " + instClass.getName() + ", problem: " + msg); }
/** * Helper method for constructing instantiation exception for specified type, to indicate problem * with physically constructing instance of specified class (missing constructor, exception from * constructor) */ public JsonMappingException instantiationException(Class<?> instClass, Throwable t) { return JsonMappingException.from( _parser, "Can not construct instance of " + instClass.getName() + ", problem: " + t.getMessage(), t); }
/** * Helper method for constructing generic mapping exception with specified message and current * location information */ public JsonMappingException mappingException(String message) { return JsonMappingException.from(getParser(), message); }
public JsonMappingException mappingException(Class<?> targetClass, JsonToken token) { String clsName = _calcName(targetClass); return JsonMappingException.from( _parser, "Can not deserialize instance of " + clsName + " out of " + token + " token"); }
/** Helper method for indicating that the current token was expected to be another token. */ public JsonMappingException wrongTokenException(JsonParser jp, JsonToken expToken, String msg) { return JsonMappingException.from( jp, "Unexpected token (" + jp.getCurrentToken() + "), expected " + expToken + ": " + msg); }