List of usage examples for com.fasterxml.jackson.core JsonToken END_OBJECT
JsonToken END_OBJECT
To view the source code for com.fasterxml.jackson.core JsonToken END_OBJECT.
Click Source Link
From source file:org.apache.batchee.jackson.JacksonJsonReader.java
@Override protected Object doRead() throws Exception { JsonToken token;//from w w w. j a v a 2 s . c o m do { token = parser.nextToken(); } while ((token != JsonToken.START_OBJECT && token != end) || (end == null && (token == JsonToken.END_ARRAY || token == JsonToken.END_OBJECT))); if (clazz == null) { parser.readValueAsTree(); } return parser.readValueAs(clazz); }
From source file:ai.susi.geo.GeoJsonReader.java
@Override public void run() { // using a streamparser to be able to handle very large input files try {//from w w w . jav a2 s . c om JsonToken token; while (!parser.isClosed() && (token = parser.nextToken()) != null && token != JsonToken.END_OBJECT) { String name = parser.getCurrentName(); if (JsonToken.FIELD_NAME.equals(token) && "type".equals(name)) { parser.nextToken(); //System.out.println(parser.getText()); continue; } if (JsonToken.FIELD_NAME.equals(token) && "features".equals(name)) { token = parser.nextToken(); if (!JsonToken.START_ARRAY.equals(token)) break; while (!parser.isClosed() && (token = parser.nextToken()) != null && token != JsonToken.END_ARRAY) { Feature feature = new Feature(parser); //System.out.println(feature.toString()); try { this.featureQueue.put(feature); } catch (InterruptedException e) { Log.getLog().warn(e); } } } } } catch (IOException e) { Log.getLog().warn(e); } finally { for (int i = 0; i < this.concurrency; i++) { try { this.featureQueue.put(POISON_FEATURE); } catch (InterruptedException e) { } } } }
From source file:internal.product.ProductImportResource.java
@POST @Produces(MediaType.APPLICATION_JSON)//from w w w .j av a 2 s . c o m @Path("/batch") public Response batch(InputStream batch, @Context HttpServletRequest request) { try { JsonParser parser = jfactory.createParser(batch); while (parser.nextToken() != JsonToken.END_OBJECT) { System.out.println(parser.getCurrentToken()); } } catch (IOException e) { return Response.status(Status.INTERNAL_SERVER_ERROR).entity(UTF8.encode(e.toString())).build(); } return Response.status(Status.OK).entity(UTF8.encode("Hello world:")).build(); }
From source file:no.ssb.jsonstat.v2.deser.DimensionDeserializer.java
@Override public Dimension.Builder deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { // Get the name first. String name = parseName(p, ctxt); if (p.getCurrentToken() == JsonToken.START_OBJECT) { p.nextToken();// w w w . ja v a2s .c om } Dimension.Builder dimension; dimension = Dimension.create(name); while (p.nextValue() != JsonToken.END_OBJECT) { switch (p.getCurrentName()) { case "category": parseCategory(dimension, p, ctxt); break; case "label": dimension.withLabel(parseLabel(p, ctxt)); break; default: ctxt.handleUnknownProperty(p, this, Dimension.Builder.class, p.getCurrentName()); break; } } return dimension; }
From source file:com.cinnober.msgcodec.json.TypeScannerJsonParserTest.java
@Test public void test2() throws IOException { JsonParser p = new JsonFactory().createParser("{\"a\":1, \"b\":1.1, \"$type\":\"x\"}"); p.nextToken(); // START_OBJECT p.nextToken(); // FIELD_NAME TypeScannerJsonParser p2 = new TypeScannerJsonParser(p); assertEquals("x", p2.findType()); assertNextField("a", p2); assertNextIntValue(1, p2);//from w ww .j a v a 2s .c o m assertNextField("b", p2); assertNextFloatValue(1.1, p2); assertEquals(JsonToken.END_OBJECT, p2.nextToken()); assertNull(p2.nextToken()); }
From source file:com.cedarsoft.serialization.jackson.IgnoringSerializer.java
@Nonnull private static JsonToken findOutToken(@Nonnull JsonToken inToken) { switch (inToken) { case START_OBJECT: return JsonToken.END_OBJECT; case START_ARRAY: return JsonToken.END_ARRAY; }/*from w ww . ja va 2 s . c o m*/ throw new SerializationException(SerializationException.Details.INVALID_STATE, "No end token found for <" + inToken + ">"); }
From source file:org.debezium.core.doc.JacksonReader.java
private Document parseDocument(JsonParser parser, boolean nested) throws IOException { // Iterate over the fields in the top-level document ... BasicDocument doc = new BasicDocument(); JsonToken token = null;/*from ww w . j a v a 2 s. co m*/ if (!nested) { // We expect the START_OBJECT token ... token = parser.nextToken(); if (!nested && token != JsonToken.START_OBJECT) { throw new IOException("Expected data to start with an Object, but was " + token); } } String fieldName = null; token = parser.nextToken(); while (token != JsonToken.END_OBJECT) { switch (token) { case FIELD_NAME: fieldName = parser.getCurrentName(); break; case START_OBJECT: doc.setDocument(fieldName, parseDocument(parser, true)); break; case START_ARRAY: doc.setArray(fieldName, parseArray(parser)); break; case VALUE_STRING: doc.setString(fieldName, parser.getValueAsString()); break; case VALUE_TRUE: doc.setBoolean(fieldName, true); break; case VALUE_FALSE: doc.setBoolean(fieldName, false); break; case VALUE_NULL: doc.setNull(fieldName); break; case VALUE_NUMBER_FLOAT: case VALUE_NUMBER_INT: switch (parser.getNumberType()) { case FLOAT: doc.setNumber(fieldName, parser.getFloatValue()); break; case DOUBLE: doc.setNumber(fieldName, parser.getDoubleValue()); break; case BIG_DECIMAL: doc.setNumber(fieldName, parser.getDecimalValue()); break; case INT: doc.setNumber(fieldName, parser.getIntValue()); break; case LONG: doc.setNumber(fieldName, parser.getLongValue()); break; case BIG_INTEGER: doc.setNumber(fieldName, parser.getBigIntegerValue()); break; } break; case VALUE_EMBEDDED_OBJECT: // disregard this, since it's an extension ... break; case NOT_AVAILABLE: throw new JsonParseException("Non-blocking parsers are not supported", parser.getCurrentLocation()); case END_ARRAY: throw new JsonParseException("Not expecting an END_ARRAY token", parser.getCurrentLocation()); case END_OBJECT: throw new JsonParseException("Not expecting an END_OBJECT token", parser.getCurrentLocation()); } token = parser.nextToken(); } return doc; }
From source file:com.sdl.odata.unmarshaller.json.core.JsonProcessor.java
/** * Initialize processor, automatically scanning the input JSON. * @throws ODataUnmarshallingException If unable to initialize *//*from w ww .j a v a2 s . co m*/ public void initialize() throws ODataUnmarshallingException { LOG.info("Parser is initializing"); try { JsonParser jsonParser = JSON_FACTORY.createParser(inputJson); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String token = jsonParser.getCurrentName(); if (token != null) { if (token.startsWith(ODATA)) { processSpecialTags(jsonParser); } else if (token.endsWith(ODATA_BIND)) { processLinks(jsonParser); } else { process(jsonParser); } } } } catch (IOException e) { throw new ODataUnmarshallingException("It is unable to unmarshall", e); } }
From source file:name.gumartinm.weather.information.parser.JPOSCurrentParser.java
private void getCurrentWeatherData(final Current currentWeatherData, final JsonParser jParser) throws JsonParseException, IOException { if (jParser.nextToken() == JsonToken.START_OBJECT) { while (jParser.nextToken() != JsonToken.END_OBJECT) { final String fieldname = jParser.getCurrentName(); final JsonToken nextToken = jParser.nextToken(); if (nextToken == JsonToken.START_OBJECT) { this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname); }// ww w . ja va 2 s . c o m if (nextToken == JsonToken.START_ARRAY) { JsonToken tokenNext = jParser.nextToken(); while (tokenNext != JsonToken.END_ARRAY) { if (tokenNext == JsonToken.START_OBJECT) { this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname); } tokenNext = jParser.nextToken(); } } if ((nextToken == JsonToken.VALUE_NUMBER_INT) || (nextToken == JsonToken.VALUE_STRING)) { this.getCurrentWeatherDataObjects(currentWeatherData, jParser, fieldname); } } } }