@Override public void readFIntArr(int len, int[] arr) throws IOException { JsonToken jsonToken = input.nextToken(); if ( ! jsonToken.isStructStart() ) throw new RuntimeException("Expected array start"); for (int i = 0; i < len; i++) { input.nextToken(); arr[i] = input.getIntValue(); } }
@Override public void readFIntArr(int len, int[] arr) throws IOException { JsonToken jsonToken = input.nextToken(); if ( ! jsonToken.isStructStart() ) throw new RuntimeException("Expected array start"); for (int i = 0; i < len; i++) { input.nextToken(); arr[i] = input.getIntValue(); } }
/** * Need to override, re-implement similar to how method defined in * {@link com.fasterxml.jackson.core.base.ParserMinimalBase}, to keep * state correct here. */ @Override public JsonParser skipChildren() throws IOException { if ((_currToken != JsonToken.START_OBJECT) && (_currToken != JsonToken.START_ARRAY)) { return this; } int open = 1; // Since proper matching of start/end markers is handled // by nextToken(), we'll just count nesting levels here while (true) { JsonToken t = nextToken(); if (t == null) { // not ideal but for now, just return return this; } if (t.isStructStart()) { ++open; } else if (t.isStructEnd()) { if (--open == 0) { return this; } } } }
if (t.isStructStart()) { ++open; } else if (t.isStructEnd()) {
/** * Need to override, re-implement similar to how method defined in * {@link com.fasterxml.jackson.core.base.ParserMinimalBase}, to keep * state correct here. */ @Override public JsonParser skipChildren() throws IOException { if ((_currToken != JsonToken.START_OBJECT) && (_currToken != JsonToken.START_ARRAY)) { return this; } int open = 1; // Since proper matching of start/end markers is handled // by nextToken(), we'll just count nesting levels here while (true) { JsonToken t = nextToken(); if (t == null) { // not ideal but for now, just return return this; } if (t.isStructStart()) { ++open; } else if (t.isStructEnd()) { if (--open == 0) { return this; } } } }
if (t.isStructStart()) { ++open; } else if (t.isStructEnd()) {
/** * Need to override, re-implement similar to how method defined in * {@link com.fasterxml.jackson.core.base.ParserMinimalBase}, to keep * state correct here. */ @Override public JsonParser skipChildren() throws IOException { if ((delegate.currentToken() != JsonToken.START_OBJECT) && (delegate.currentToken() != JsonToken.START_ARRAY)) { return this; } int open = 1; // Since proper matching of start/end markers is handled // by nextToken(), we'll just count nesting levels here while (true) { JsonToken t = nextToken(); if (t == null) { // not ideal but for now, just return return this; } if (t.isStructStart()) { ++open; } else if (t.isStructEnd()) { if (--open == 0) { return this; } } } }
throw new RuntimeException("expected value attribute for object of type:"+type); if ( ! input.nextToken().isStructStart() ) { throw new RuntimeException("expected struct start"); throw new RuntimeException("expected value attribute for object of type:"+type); if ( ! input.nextToken().isStructStart() ) { throw new RuntimeException("expected array start");
/** * Need to override, re-implement similar to how method defined in * {@link com.fasterxml.jackson.core.base.ParserMinimalBase}, to keep * state correct here. */ @Override public JsonParser skipChildren() throws IOException { if ((delegate.currentToken() != JsonToken.START_OBJECT) && (delegate.currentToken() != JsonToken.START_ARRAY)) { return this; } int open = 1; // Since proper matching of start/end markers is handled // by nextToken(), we'll just count nesting levels here while (true) { JsonToken t = nextToken(); if (t == null) { // not ideal but for now, just return return this; } if (t.isStructStart()) { ++open; } else if (t.isStructEnd()) { if (--open == 0) { return this; } } } }
throw new RuntimeException("expected value attribute for object of type:"+type); if ( ! input.nextToken().isStructStart() ) { throw new RuntimeException("expected struct start"); throw new RuntimeException("expected value attribute for object of type:"+type); if ( ! input.nextToken().isStructStart() ) { throw new RuntimeException("expected array start");
public Shape read(JsonParser jp, ShapeFactory factory) throws IOException { if(!jp.getCurrentToken().isStructStart()) { throw new JsonParseException(jp, "Expect the start of GeoJSON Geometry object"); } return read( (ObjectNode)jp.getCodec().readTree(jp), factory ); }
@Override public Shape deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if(t.isStructStart()) { return read( jp, ctx.getShapeFactory() ); } if (t.isScalarValue()) { String txt = t.asString(); if(txt!=null && txt.length()>0) { try { return ctx.getFormats().read(txt); } catch (Exception e) { throw new JsonParseException(jp, "error reading shape", e); } } return null; // empty string } throw new JsonParseException(jp, "can't read GeoJSON yet"); } }
private int nestingOffset(JsonToken t) { if (t.isStructStart()) { return 1; } else if (t.isStructEnd()) { return -1; } else { return 0; } }
private static boolean isEmpty(byte[] buffer, int len) { if (len == 0) { return true; } // Test for "logically empty" (e.g. "{}" or "[]") try { JsonParser jp = JSON_FACTORY.createParser(buffer, 0, len); return jp.nextToken().isStructStart() && jp.nextToken().isStructEnd(); } catch (IOException e) { return false; } }
private static void ignoreValue(@Nonnull JsonParser jp) throws IOException { JsonToken token = jp.getCurrentToken(); if (!token.isStructStart()) { return; // skip primitive value in one turn } // skip structure, keeping in mind that braces should be balanced int nesting = 1; for (;;) { token = jp.nextToken(); if (token.isStructEnd()) { --nesting; if (nesting == 0) { break; } } else if (token.isStructStart()) { ++nesting; } } }
private boolean isValueToken(JsonToken previousToken) { return !(previousToken.isStructEnd() || previousToken.isStructStart() || previousToken == JsonToken.FIELD_NAME); } }
protected void convert( InputStream in, OutputStream out, JsonFactory inFormat, JsonFactory outFormat) throws Exception { final JsonParser parser = inFormat.createParser(in); final JsonGenerator generator = outFormat.createGenerator(out, JSON_ENCODING); final JsonToken token = parser.nextToken(); if (!token.isStructStart() && !token.isScalarValue()) { throw new RuntimeException( "Document does not begin with an object, an array, or a scalar value"); } generator.copyCurrentStructure(parser); if (parser.nextToken() != null) { throw new RuntimeException("Document has more content than a single object/array"); } generator.flush(); } }
protected static void skipValue(JsonParser p) throws IOException, JsonParseException { if (p.getCurrentToken().isStructStart()) { p.skipChildren(); // will leave parser at end token (e.g. '}' or ']') p.nextToken(); } else if (p.getCurrentToken().isScalarValue()) { p.nextToken(); } else { throw new JsonParseException(p, "Can't skip JSON value token: " + p.getCurrentToken()); } }
protected static void skipFields(JsonParser p) throws IOException, JsonParseException { while (p.getCurrentToken() != null && !p.getCurrentToken().isStructEnd()) { if (p.getCurrentToken().isStructStart()) { p.skipChildren(); } else if (p.getCurrentToken() == JsonToken.FIELD_NAME) { p.nextToken(); } else if (p.getCurrentToken().isScalarValue()) { p.nextToken(); } else { throw new JsonParseException(p, "Can't skip token: " + p.getCurrentToken()); } } } }
/** * Skips a field name if necessary, returning the current token then, which must be * the start of an Array or Object: '{' or '['. */ public static JsonToken peekStructStart(JsonParser par) throws IOException { JsonToken token = peekToken(par); if (token.isStructStart()) { return token; } else { throw new JsonParseException(par, "Expected start of array or object"); } }