Refine search
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); } }
protected JsonLocation _locationFor(Mark m) { if (m == null) { return new JsonLocation(_ioContext.getSourceReference(), -1, -1, -1); } return new JsonLocation(_ioContext.getSourceReference(), -1, m.getLine() + 1, // from 0- to 1-based m.getColumn() + 1); // ditto }
@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; }
Builder setLocation(JsonLocation location) { return location == null ? this : setLocation(location.getLineNr(), location.getColumnNr()); }
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(); }
@Override public List<NotificationAttribute> deserialize(JsonParser parser, DeserializationContext ctx) throws JsonParseException, IOException { List<NotificationAttribute> result = new ArrayList<NotificationAttribute>(); JsonToken token = parser.getCurrentToken(); // v1.0: array of objects if (token == JsonToken.START_ARRAY) { NotificationAttribute[] attributes = parser.readValueAs(NotificationAttribute[].class); result.addAll(Arrays.asList(attributes)); } else if (token == JsonToken.START_OBJECT) { // v2.0: series of string arrays while (parser.nextToken() != JsonToken.END_OBJECT) { NotificationAttribute attr = new NotificationAttribute(); attr.setName(parser.getCurrentName()); parser.nextToken(); // Should be the array of values String[] values = parser.readValueAs(String[].class); attr.setValues(Arrays.asList(values)); result.add(attr); } } else throw new IllegalArgumentException("Invalid attributes value. Expected array of NotificationAttribute" + " objects or object with a series of string arrays. See https://issues.jasig.org/browse/NOTIFPLT-32" + " for format." + parser.getCurrentLocation().toString()); return result; }
private void acceptEndArray(JsonParser p) throws IOException { if (p.getCurrentToken() == JsonToken.END_ARRAY) { return; } if (p.nextToken() != JsonToken.END_ARRAY) { throw new IOException("malformed document, expected array end but found " + p.getCurrentToken() + " at " + p.getCurrentLocation().toString()); } }
parser = new JsonFactory().createJsonParser(inputStream); parser.setCodec(new ObjectMapper()); token = parser.nextToken(); parser.getCurrentName() != null && parser.getCurrentName().equals("features"))) { token = parser.nextToken(); key.set(parser.getCurrentLocation().getCharOffset()); token = parser.nextToken();
private void readArrayValues(CompositeResource res, JsonParser p) throws IOException { JsonToken next = p.nextToken(); if (null == next) { throw new IOException("malformed document, not a supported array value at " + p.getCurrentLocation().toString()); } else switch (next) { case VALUE_STRING: res.value = p.getText(); break; case START_ARRAY: if (p.nextToken() == JsonToken.END_ARRAY) { res.value = Collections.EMPTY_LIST; } else { ArrayList<String> a = new ArrayList<>(); res.value = a; do { a.add(p.getText()); } while (p.nextToken() != JsonToken.END_ARRAY); } break; default: throw new IOException("malformed document, not a supported array value at " + p.getCurrentLocation().toString()); } }
private EventList readEvents(JsonParser jp, Event.EventContext context, DeserializationContext deserializationContext) throws IOException { Object inputSource = jp.getInputSource(); long start = jp.getTokenLocation().getByteOffset(); if (jp.getCurrentToken() != JsonToken.START_ARRAY) { throw new RakamException("events field must be array", BAD_REQUEST); long end = jp.getTokenLocation().getByteOffset(); Object sourceRef = jp.getTokenLocation().getSourceRef(); if (sourceRef instanceof byte[]) { validateChecksum((byte[]) sourceRef, start, end, context);
private void acceptStartArray(JsonParser p) throws IOException { if (p.nextToken() != JsonToken.START_ARRAY) { throw new IOException("malformed document, expected array at " + p.getCurrentLocation().toString()); } }
private static int findJsonEndBoundary(String plan, int indexInPlan) throws IOException { // read the json pushdown query with jackson to find it's total length, wasn't sure how to do this with just regex // as it will span across a variable number of lines ObjectMapper map = new ObjectMapper(); //for later inner object data binding JsonParser p = map.getFactory().createParser(plan.substring(indexInPlan)); JsonToken token = p.nextToken(); if (token != JsonToken.START_ARRAY) { throw new RuntimeException("Error finding elastic pushdown query JSON in plan text, " + "did not find start array as expected, instead found " + token); } int startEndCounter = 1; while (startEndCounter != 0) { token = p.nextToken(); if (token == JsonToken.START_ARRAY) { startEndCounter++; } else if (token == JsonToken.END_ARRAY) { startEndCounter--; } } long pushdownEndIndexInPlan = p.getTokenLocation().getCharOffset() + 1; return indexInPlan + (int) pushdownEndIndexInPlan; }
/** * {@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() ); } }
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()); }
/** * Gets the current line number. * @return the line number */ public int getLineNum() { return (parser == null) ? 0 : parser.getCurrentLocation().getLineNr(); }
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); } }
public PositionEndpoint(JsonLocation location) { this(location.getCharOffset(), location.getLineNr(), location.getColumnNr()); }
public JSONException(Exception e, JsonLocation location) { super(e); this.location = location.toString(); this.line = location.getLineNr(); this.column = location.getColumnNr(); }
@Override public XContentLocation getTokenLocation() { JsonLocation loc = parser.getTokenLocation(); if (loc == null) { return null; } return new XContentLocation(loc.getLineNr(), loc.getColumnNr()); }
@Override public String toString() { JsonLocation location = parser.getCurrentLocation(); return getClass().getSimpleName() + "[Line=" + location.getLineNr() + ", Column=" + (location.getColumnNr() + 1) + ", Field=" + getCurrentField() + "]"; }