public JsonLocation findLocation() { // ugly but: if (_source instanceof JsonParser) { return ((JsonParser)_source).getCurrentLocation(); } // do generators have a way to provide Location? Apparently not... return null; }
/** * Constructor that uses current parsing location as location, and * sets processor (accessible via {@link #getProcessor()}) to * specified parser. * * @since 2.7 */ public JsonParseException(JsonParser p, String msg) { super(msg, (p == null) ? null : p.getCurrentLocation()); _processor = p; }
/** * @since 2.7 */ public JsonParseException(JsonParser p, String msg, Throwable root) { super(msg, (p == null) ? null : p.getCurrentLocation(), root); _processor = p; }
/** * Convenience method, functionally equivalent to: *<code> * iterator.getParser().getCurrentLocation() *</code> * * @return Location of the input stream of the underlying parser * * @since 2.2.1 */ public JsonLocation getCurrentLocation() { return _parser.getCurrentLocation(); }
@Override public JsonLocation getCurrentLocation() { return delegate.getCurrentLocation(); } @Override public JsonStreamContext getParsingContext() { return delegate.getParsingContext(); }
@Override public JsonLocation getCurrentLocation() { return delegate.getCurrentLocation(); }
public JsonLocation findLocation() { // ugly but: if (_source instanceof JsonParser) { return ((JsonParser)_source).getCurrentLocation(); } // do generators have a way to provide Location? Apparently not... return null; }
public StreamReadException(JsonParser p, String msg) { super(msg, (p == null) ? null : p.getCurrentLocation()); _processor = p; }
public StreamReadException(JsonParser p, String msg, Throwable root) { super(msg, (p == null) ? null : p.getCurrentLocation(), root); _processor = p; }
@Override public int getInputPos() { JsonLocation currentLocation = input.getCurrentLocation(); long byteOffset = currentLocation.getByteOffset(); if ( input.getCurrentToken() == JsonToken.FIELD_NAME ) byteOffset-=2; // eager parsing of jackson ':' + '['/'{' return (int) byteOffset; }
@Override public Application deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String name = null; List<InstanceInfo> instances = new ArrayList<>(); while (jp.nextToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); // to point to value if ("name".equals(fieldName)) { name = jp.getValueAsString(); } else if ("instance".equals(fieldName)) { instances.add(jp.readValueAs(InstanceInfo.class)); } else { throw new JsonMappingException("Unexpected field " + fieldName, jp.getCurrentLocation()); } } return new Application(name, instances); } }
@Override public int getInputPos() { JsonLocation currentLocation = input.getCurrentLocation(); long byteOffset = currentLocation.getByteOffset(); if ( input.getCurrentToken() == JsonToken.FIELD_NAME ) byteOffset-=2; // eager parsing of jackson ':' + '['/'{' return (int) byteOffset; }
@Override public InstanceInfo.PortWrapper deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { boolean enabled = false; int port = 0; while (jp.nextToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); // to point to value if ("enabled".equals(fieldName)) { enabled = Boolean.valueOf(jp.getValueAsString()); } else if (fieldName == null || "".equals(fieldName)) { String value = jp.getValueAsString(); port = value == null ? 0 : Integer.parseInt(value); } else { throw new JsonMappingException("Unexpected field " + fieldName, jp.getCurrentLocation()); } } return new InstanceInfo.PortWrapper(enabled, port); } }
@Override public Date deserialize(JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { String value = jp.getValueAsString().replaceFirst("0000Z$", ""); try { return simpleDateFormat.parse(value); } catch (ParseException e) { throw new InvalidFormatException( "Can't parse date at offset " + e.getErrorOffset(), jp.getCurrentLocation(), value, Date.class); // throw new RuntimeException("Can't parse date at offset " + e.getErrorOffset(), e); } } }
@Override @SuppressWarnings("unchecked") public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode json = treeObjectMapper.readTree(jp); if (!json.isObject()) { throw new JsonMappingException("Expected object to deserialize DataSource", jp.getCurrentLocation()); } return (T) new DataSourceImpl(model, (ObjectNode) json); } }
private Object parseInternal(JsonParser parser) throws SerDeException { try { parser.nextToken(); Object res = parseDispatcher(parser, oi); return res; } catch (Exception e) { String locationStr = parser.getCurrentLocation().getLineNr() + "," + parser.getCurrentLocation().getColumnNr(); throw new SerDeException("at[" + locationStr + "]: " + e.getMessage(), e); } }
/** * Factory method used for constructing instances of this exception type. * * @param p Underlying parser used for reading input being used for data-binding * @param fromObjectOrClass Reference to either instance of problematic type ( * if available), or if not, type itself * @param propertyName Name of unrecognized property * @param propertyIds (optional, null if not available) Set of properties that * type would recognize, if completely known: null if set cannot be determined. */ public static UnrecognizedPropertyException from(JsonParser p, Object fromObjectOrClass, String propertyName, Collection<Object> propertyIds) { Class<?> ref; if (fromObjectOrClass instanceof Class<?>) { ref = (Class<?>) fromObjectOrClass; } else { ref = fromObjectOrClass.getClass(); } String msg = String.format("Unrecognized field \"%s\" (class %s), not marked as ignorable", propertyName, ref.getName()); UnrecognizedPropertyException e = new UnrecognizedPropertyException(p, msg, p.getCurrentLocation(), ref, propertyName, propertyIds); // but let's also ensure path includes this last (missing) segment e.prependPath(fromObjectOrClass, propertyName); return e; } }
private String getLocationString() { JsonLocation l = parser.getCurrentLocation(); List<String> parts = new ArrayList<>(4); parts.add("line: " + l.getLineNr()); parts.add("column: " + l.getColumnNr()); if (l.getByteOffset() >= 0) { parts.add("byte offset: " + l.getByteOffset()); } return parts.toString(); }
/** * Method called in cases where it looks like we got an Object Id * to parse and use as a reference. */ protected Object _deserializeFromObjectId(JsonParser p, DeserializationContext ctxt) throws IOException { Object id = _objectIdReader.readObjectReference(p, ctxt); ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver); // do we have it resolved? Object pojo = roid.resolve(); if (pojo == null) { // not yet; should wait... throw new UnresolvedForwardReference(p, "Could not resolve Object Id ["+id+"] -- unresolved forward-reference?", p.getCurrentLocation(), roid); } return pojo; } }
/** * Method called in cases where it looks like we got an Object Id * to parse and use as a reference. */ protected Object deserializeFromObjectId(JsonParser p, DeserializationContext ctxt) throws IOException { Object id = _objectIdReader.readObjectReference(p, ctxt); ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver); // do we have it resolved? Object pojo = roid.resolve(); if (pojo == null) { // not yet; should wait... throw new UnresolvedForwardReference(p, "Could not resolve Object Id ["+id+"] (for "+_beanType+").", p.getCurrentLocation(), roid); } return pojo; }