List of usage examples for com.fasterxml.jackson.core JsonParser nextToken
public abstract JsonToken nextToken() throws IOException, JsonParseException;
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); }//from www . j a v a 2 s. co 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); } } } }
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.ReferentialConstraintRoleDeserializer.java
@Override public ReferentialConstraintRole deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final ReferentialConstraintRole refConstRole = new ReferentialConstraintRole(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Role".equals(jp.getCurrentName())) { refConstRole.setRole(jp.nextTextValue()); } else if ("PropertyRef".equals(jp.getCurrentName())) { jp.nextToken();/* w ww . j ava 2 s . c o m*/ refConstRole.getPropertyRefs().add(jp.getCodec().readValue(jp, PropertyRef.class)); } } } return refConstRole; }
From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java
@Test public void testFloat64DecodePosInfinity() throws IOException { JsonParser p = f.createParser("\"Infinity\""); p.nextToken(); assertTrue(Double.POSITIVE_INFINITY == JsonValueHandler.FLOAT64.readValue(p)); }
From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java
@Test public void testFloat32DecodePosInfinity() throws IOException { JsonParser p = f.createParser("\"Infinity\""); p.nextToken(); assertTrue(Float.POSITIVE_INFINITY == JsonValueHandler.FLOAT32.readValue(p)); }
From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java
@Test public void testFloat64DecodeNegInfinity() throws IOException { JsonParser p = f.createParser("\"-Infinity\""); p.nextToken(); assertTrue(Double.NEGATIVE_INFINITY == JsonValueHandler.FLOAT64.readValue(p)); }
From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java
@Test public void testFloat32DecodeNegInfinity() throws IOException { JsonParser p = f.createParser("\"-Infinity\""); p.nextToken(); assertTrue(Float.NEGATIVE_INFINITY == JsonValueHandler.FLOAT32.readValue(p)); }
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.SchemaDeserializer.java
@Override public Schema deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final Schema schema = new Schema(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Namespace".equals(jp.getCurrentName())) { schema.setNamespace(jp.nextTextValue()); } else if ("Alias".equals(jp.getCurrentName())) { schema.setAlias(jp.nextTextValue()); } else if ("Using".equals(jp.getCurrentName())) { jp.nextToken();//from w ww. j ava 2 s. c om schema.getUsings().add(jp.getCodec().readValue(jp, Using.class)); } else if ("Association".equals(jp.getCurrentName())) { jp.nextToken(); schema.getAssociations().add(jp.getCodec().readValue(jp, Association.class)); } else if ("ComplexType".equals(jp.getCurrentName())) { jp.nextToken(); schema.getComplexTypes().add(jp.getCodec().readValue(jp, ComplexType.class)); } else if ("EntityType".equals(jp.getCurrentName())) { jp.nextToken(); schema.getEntityTypes().add(jp.getCodec().readValue(jp, EntityType.class)); } else if ("EnumType".equals(jp.getCurrentName())) { jp.nextToken(); schema.getEnumTypes().add(jp.getCodec().readValue(jp, EnumType.class)); } else if ("ValueTerm".equals(jp.getCurrentName())) { jp.nextToken(); schema.getValueTerms().add(jp.getCodec().readValue(jp, ValueTerm.class)); } else if ("EntityContainer".equals(jp.getCurrentName())) { jp.nextToken(); schema.getEntityContainers().add(jp.getCodec().readValue(jp, EntityContainer.class)); } else if ("Annotations".equals(jp.getCurrentName())) { jp.nextToken(); schema.getAnnotations().add(jp.getCodec().readValue(jp, Annotations.class)); } } } return schema; }
From source file:automenta.knowtention.model.JSONObjectMetrics.java
public JSONObjectMetrics(JsonNode n) { this.when = System.currentTimeMillis(); this.channel = null; JsonParser parser = n.traverse(); error = true;// w ww .java 2 s . c o m while (!parser.isClosed()) { try { JsonToken t = parser.nextToken(); if (t == null) break; switch (t) { case VALUE_STRING: numValues++; numStrings++; String s = parser.getValueAsString(); if (s != null) stringLengthSum += s.length(); break; case VALUE_EMBEDDED_OBJECT: numValues++; numEmbeddedObjects++; break; case VALUE_FALSE: case VALUE_TRUE: numValues++; numBooleans++; break; case VALUE_NUMBER_FLOAT: case VALUE_NUMBER_INT: numNumbers++; numValues++; break; case VALUE_NULL: numValues++; numNulls++; break; } if (t == null) break; numTokens++; } catch (IOException ex) { break; } } error = false; }
From source file:name.gumartinm.weather.information.parser.JPOSForecastParser.java
private void getForecastWeatherData(final Forecast forecastWeatherData, 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.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname); }/*from w ww.j a v a 2 s . c om*/ if (nextToken == JsonToken.START_ARRAY) { JsonToken tokenNext = jParser.nextToken(); while (tokenNext != JsonToken.END_ARRAY) { if (tokenNext == JsonToken.START_OBJECT) { this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname); } tokenNext = jParser.nextToken(); } } if ((nextToken == JsonToken.VALUE_NUMBER_INT) || (nextToken == JsonToken.VALUE_STRING)) { this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname); } } } }
From source file:ch.rasc.wampspring.message.PublishMessage.java
public PublishMessage(JsonParser jp, WampSession wampSession) throws IOException { super(WampMessageType.PUBLISH); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }/*from w w w . ja v a 2s . c o m*/ setTopicURI(replacePrefix(jp.getValueAsString(), wampSession)); jp.nextToken(); this.event = jp.readValueAs(Object.class); if (jp.nextToken() != JsonToken.END_ARRAY) { if (jp.getCurrentToken() == JsonToken.VALUE_TRUE || jp.getCurrentToken() == JsonToken.VALUE_FALSE) { this.excludeMe = jp.getValueAsBoolean(); this.exclude = null; this.eligible = null; if (jp.nextToken() != JsonToken.END_ARRAY) { // Wrong message format, excludeMe should not be followed by // any value throw new IOException(); } } else { this.excludeMe = null; TypeReference<Set<String>> typRef = new TypeReference<Set<String>>() { // nothing here }; if (jp.getCurrentToken() != JsonToken.START_ARRAY) { throw new IOException(); } this.exclude = jp.readValueAs(typRef); if (jp.nextToken() == JsonToken.START_ARRAY) { this.eligible = jp.readValueAs(typRef); } else { this.eligible = null; } } } else { this.excludeMe = null; this.exclude = null; this.eligible = null; } }