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:com.cedarsoft.serialization.test.performance.XmlParserPerformance.java
private void benchParse(@Nonnull JsonFactory factory, @Nonnull byte[] contentSample) throws XMLStreamException, IOException { for (int i = 0; i < BIG; i++) { JsonParser parser = factory.createParser(contentSample); assertEquals(JsonToken.START_OBJECT, parser.nextToken()); assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); assertEquals("id", parser.getCurrentName()); assertEquals(JsonToken.VALUE_STRING, parser.nextToken()); String id = parser.getText(); assertEquals("Canon Raw", id); assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); assertEquals("dependent", parser.getCurrentName()); assertEquals(JsonToken.VALUE_FALSE, parser.nextToken()); boolean dependent = parser.getBooleanValue(); assertFalse(dependent);//from w w w. j a v a2 s .co m assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); assertEquals("extension", parser.getCurrentName()); assertEquals(JsonToken.START_OBJECT, parser.nextToken()); assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); assertEquals("extension", parser.getCurrentName()); assertEquals(JsonToken.VALUE_STRING, parser.nextToken()); String extension = parser.getText(); assertEquals("cr2", extension); assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); assertEquals("default", parser.getCurrentName()); assertEquals(JsonToken.VALUE_TRUE, parser.nextToken()); boolean isDefault = parser.getBooleanValue(); assertTrue(isDefault); assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); assertEquals("delimiter", parser.getCurrentName()); assertEquals(JsonToken.VALUE_STRING, parser.nextToken()); String delimiter = parser.getText(); assertEquals(".", delimiter); assertEquals(JsonToken.END_OBJECT, parser.nextToken()); assertEquals(JsonToken.END_OBJECT, parser.nextToken()); assertNull(parser.nextToken()); parser.close(); FileType type = new FileType(id, new Extension(delimiter, extension, isDefault), dependent); assertNotNull(type); } }
From source file:com.ntsync.shared.RawContact.java
private static List<RawAddressData> readAddressList(String rowId, List<RawAddressData> addresses, JsonParser jp) throws IOException { List<RawAddressData> newAddresses = addresses; while (jp.nextToken() != JsonToken.END_ARRAY) { AddressType type = null;/* w w w . j av a 2 s. co m*/ String label = null; String street = null; String city = null; String postcode = null; String country = null; String region = null; String pobox = null; String neighborhood = null; boolean isSuperPrimary = false; boolean isPrimary = false; while (jp.nextToken() != JsonToken.END_OBJECT) { String namefield = jp.getCurrentName(); // move to value if (jp.nextToken() == null) { throw new JsonParseException("Invalid JSON-Structure. End of Array missing.", jp.getCurrentLocation()); } if (ContactConstants.NEIGHBORHOOD.equals(namefield)) { neighborhood = jp.getValueAsString(); } else if (ContactConstants.TYPE.equals(namefield)) { type = AddressType.fromVal(jp.getValueAsInt()); } else if (ContactConstants.SUPERPRIMARY.equals(namefield)) { isSuperPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.PRIMARY.equals(namefield)) { isPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.LABEL.equals(namefield)) { label = jp.getValueAsString(); } else if (ContactConstants.STREET.equals(namefield)) { street = jp.getValueAsString(); } else if (ContactConstants.REGION.equals(namefield)) { region = jp.getValueAsString(); } else if (ContactConstants.CITY.equals(namefield)) { city = jp.getValueAsString(); } else if (ContactConstants.POSTCODE.equals(namefield)) { postcode = jp.getValueAsString(); } else if (ContactConstants.COUNTRY.equals(namefield)) { country = jp.getValueAsString(); } else if (ContactConstants.REGION.equals(namefield)) { region = jp.getValueAsString(); } else if (ContactConstants.POBOX.equals(namefield)) { pobox = jp.getValueAsString(); } else { LOG.error(JSON_FIELDNOTRECOGNIZED + rowId + " Fieldname:" + namefield); } } if (newAddresses == null) { newAddresses = new ArrayList<RawAddressData>(); } if (type == null) { type = AddressType.TYPE_OTHER; } newAddresses.add(new RawAddressData(type, label, isPrimary, isSuperPrimary, street, pobox, neighborhood, city, region, postcode, country)); } return newAddresses; }
From source file:com.ntsync.shared.RawContact.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T extends ListType> List<ListRawData<T>> readJsonList(String rowId, List<ListRawData<T>> listData, JsonParser jp, String fieldname, ListType defaultType, Class<T> typeClass) throws IOException { List<ListRawData<T>> newListData = listData; while (jp.nextToken() != JsonToken.END_ARRAY) { String number = null;//from www. j a va 2 s. c o m ListType type = defaultType; String label = null; boolean isSuperPrimary = false; boolean isPrimary = false; while (jp.nextToken() != JsonToken.END_OBJECT) { String namefield = jp.getCurrentName(); // move to value if (jp.nextToken() == null) { throw new JsonParseException("Invalid JSON-Structure. End of Array missing.", jp.getCurrentLocation()); } if (ContactConstants.DATA.equals(namefield)) { number = jp.getValueAsString(); } else if (ContactConstants.TYPE.equals(namefield)) { type = ContactConstants.fromVal(typeClass, jp.getValueAsInt()); if (type == null) { type = defaultType; } } else if (ContactConstants.SUPERPRIMARY.equals(namefield)) { isSuperPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.PRIMARY.equals(namefield)) { isPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.LABEL.equals(namefield)) { label = jp.getValueAsString(); } else { LOG.error(JSON_FIELDNOTRECOGNIZED + rowId + " Fieldname:" + fieldname + " Unrecognized: " + namefield); break; } } if (number != null) { if (newListData == null) { newListData = new ArrayList(); } newListData.add(new ListRawData(number, type, label, isPrimary, isSuperPrimary)); } } return newListData; }
From source file:com.zenesis.qx.remote.RequestHandler.java
/** * Reads an array from JSON, where each value is of the class clazz. Note that while the result * is an array, you cannot assume that it is an array of Object, or use generics because generics * are always Objects - this is because arrays of primitive types are not arrays of Objects * @param jp/* www . j a v a 2s . c o m*/ * @param clazz * @return * @throws IOException */ private Map readMap(JsonParser jp, Class keyClazz, Class clazz) throws IOException { if (jp.getCurrentToken() == JsonToken.VALUE_NULL) return null; boolean isProxyClass = Proxied.class.isAssignableFrom(clazz); if (keyClazz == null) keyClazz = String.class; HashMap result = new HashMap(); for (; jp.nextToken() != JsonToken.END_OBJECT;) { Object key = readSimpleValue(jp, keyClazz); jp.nextToken(); if (isProxyClass) { Integer id = jp.readValueAs(Integer.class); if (id != null) { Proxied obj = getProxied(id); if (!clazz.isInstance(obj)) throw new ClassCastException( "Cannot cast " + obj + " class " + obj.getClass() + " to " + clazz); result.put(key, obj); } else result.put(key, null); } else { Object obj = readSimpleValue(jp, clazz); result.put(key, obj); } } return result; }
From source file:com.adobe.communities.ugc.migration.importer.UGCImportHelper.java
protected static void importTranslation(final JsonParser jsonParser, final Resource post) throws IOException { JsonToken token = jsonParser.getCurrentToken(); final Map<String, Object> properties = new HashMap<String, Object>(); if (token != JsonToken.START_OBJECT) { throw new IOException("expected a start object token, got " + token.asString()); }/*from w ww.j a va 2 s . c om*/ properties.put("jcr:primaryType", "social:asiResource"); Resource translationFolder = null; token = jsonParser.nextToken(); while (token == JsonToken.FIELD_NAME) { token = jsonParser.nextToken(); //advance to the field value if (jsonParser.getCurrentName().equals((ContentTypeDefinitions.LABEL_TRANSLATIONS))) { if (null == translationFolder) { // begin by creating the translation folder resource translationFolder = post.getResourceResolver().create(post, "translation", properties); } //now check to see if any translations exist if (token == JsonToken.START_OBJECT) { token = jsonParser.nextToken(); if (token == JsonToken.FIELD_NAME) { while (token == JsonToken.FIELD_NAME) { // each new field represents another translation final Map<String, Object> translationProperties = new HashMap<String, Object>(); translationProperties.put("jcr:primaryType", "social:asiResource"); String languageLabel = jsonParser.getCurrentName(); token = jsonParser.nextToken(); if (token != JsonToken.START_OBJECT) { throw new IOException("expected a start object token for translation item, got " + token.asString()); } token = jsonParser.nextToken(); while (token != JsonToken.END_OBJECT) { jsonParser.nextToken(); //get next field value if (jsonParser.getCurrentName() .equals(ContentTypeDefinitions.LABEL_TIMESTAMP_FIELDS)) { jsonParser.nextToken(); // advance to first field name while (!jsonParser.getCurrentToken().equals(JsonToken.END_ARRAY)) { final String timestampLabel = jsonParser.getValueAsString(); if (translationProperties.containsKey(timestampLabel)) { final Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(Long .parseLong((String) translationProperties.get(timestampLabel))); translationProperties.put(timestampLabel, calendar.getTime()); } jsonParser.nextToken(); } } else if (jsonParser.getCurrentName() .equals(ContentTypeDefinitions.LABEL_SUBNODES)) { jsonParser.skipChildren(); } else { translationProperties.put(jsonParser.getCurrentName(), URLDecoder.decode(jsonParser.getValueAsString(), "UTF-8")); } token = jsonParser.nextToken(); //get next field label } // add the language-specific translation under the translation folder resource Resource translation = post.getResourceResolver().create(post.getChild("translation"), languageLabel, translationProperties); if (null == translation) { throw new IOException("translation not actually imported"); } } jsonParser.nextToken(); //skip END_OBJECT token for translation } else if (token == JsonToken.END_OBJECT) { // no actual translation to import, so we're done here jsonParser.nextToken(); } } else { throw new IOException( "expected translations to be contained in an object, saw instead: " + token.asString()); } } else if (jsonParser.getCurrentName().equals("mtlanguage") || jsonParser.getCurrentName().equals("jcr:createdBy")) { properties.put(jsonParser.getCurrentName(), jsonParser.getValueAsString()); } else if (jsonParser.getCurrentName().equals("jcr:created")) { final Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(jsonParser.getLongValue()); properties.put("jcr:created", calendar.getTime()); } token = jsonParser.nextToken(); } if (null == translationFolder && properties.containsKey("mtlanguage")) { // it's possible that no translations existed, so we need to make sure the translation resource (which // includes the original post's detected language) is created anyway post.getResourceResolver().create(post, "translation", properties); } }
From source file:org.jmxtrans.embedded.output.CopperEggWriter.java
/** * read_config()/*from ww w . j a v a 2s.c om*/ * The copperegg_config.json file contains a specification for the metric groups and dashboards to be created / or updated. * Mandatory */ public void read_config(InputStream in) throws Exception { JsonFactory f = new MappingJsonFactory(); JsonParser jp = f.createJsonParser(in); JsonToken current; current = jp.nextToken(); if (current != JsonToken.START_OBJECT) { logger.warn("read_config: Error: START_OBJECT not found : quiting."); return; } current = jp.nextToken(); String fieldName = jp.getCurrentName(); current = jp.nextToken(); if (fieldName.equals("config")) { if (current != JsonToken.START_OBJECT) { logger.warn("read_config: Error: START_OBJECT not found after config : quiting."); return; } current = jp.nextToken(); String fieldName2 = jp.getCurrentName(); if (fieldName2.equals("metric_groups")) { current = jp.nextToken(); if (current != JsonToken.START_ARRAY) { logger.warn("read_config: Error: START_ARRAY not found after metric_groups : quiting."); return; } current = jp.nextToken(); while (current != JsonToken.END_ARRAY) { if (current != JsonToken.START_OBJECT) { logger.warn( "read_config: Error: START_OBJECT not found after metric_groups START_ARRAY : quiting."); return; } current = jp.nextToken(); JsonNode node1 = jp.readValueAsTree(); String node1string = write_tostring(node1); metricgroupMap.put(node1.get("name").asText(), node1string); current = jp.nextToken(); } current = jp.nextToken(); String fieldName3 = jp.getCurrentName(); if (fieldName3.equals("dashboards")) { current = jp.nextToken(); if (current != JsonToken.START_ARRAY) { logger.warn("read_config: Error: START_ARRAY not found after dashboards : quiting."); return; } current = jp.nextToken(); while (current != JsonToken.END_ARRAY) { if (current != JsonToken.START_OBJECT) { logger.warn( "read_config: Error: START_OBJECT not found after dashboards START_ARRAY : quiting."); return; } current = jp.nextToken(); JsonNode node = jp.readValueAsTree(); String nodestring = write_tostring(node); dashMap.put(node.get("name").asText(), nodestring); current = jp.nextToken(); } if (jp.nextToken() != JsonToken.END_OBJECT) { logger.warn("read_config: Error: END_OBJECT expected, not found (1): quiting."); return; } if (jp.nextToken() != JsonToken.END_OBJECT) { logger.warn("read_config: Error: END_OBJECT expected, not found (2): quiting."); return; } } else { logger.warn("read_config: Error: Expected dashboards : quiting."); return; } } else { logger.warn("read_config: Error: Expected metric_groups : quiting."); return; } } }
From source file:org.apache.hadoop.hbase.rest.TestTableScan.java
@Test public void testStreamingJSON() throws Exception { //Test with start row and end row. StringBuilder builder = new StringBuilder(); builder.append("/*"); builder.append("?"); builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1); builder.append("&"); builder.append(Constants.SCAN_START_ROW + "=aaa"); builder.append("&"); builder.append(Constants.SCAN_END_ROW + "=aay"); Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); int count = 0; ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE); JsonFactory jfactory = new JsonFactory(mapper); JsonParser jParser = jfactory.createJsonParser(response.getStream()); boolean found = false; while (jParser.nextToken() != JsonToken.END_OBJECT) { if (jParser.getCurrentToken() == JsonToken.START_OBJECT && found) { RowModel row = jParser.readValueAs(RowModel.class); assertNotNull(row.getKey()); for (int i = 0; i < row.getCells().size(); i++) { if (count == 0) { assertEquals("aaa", Bytes.toString(row.getKey())); }/* w w w .j a va2s. c om*/ if (count == 23) { assertEquals("aax", Bytes.toString(row.getKey())); } count++; } jParser.skipChildren(); } else { found = jParser.getCurrentToken() == JsonToken.START_ARRAY; } } assertEquals(24, count); }
From source file:org.apache.olingo.client.core.edm.xml.ActionDeserializer.java
@Override protected ActionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final ActionImpl action = new ActionImpl(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { action.setName(jp.nextTextValue()); } else if ("IsBound".equals(jp.getCurrentName())) { action.setBound(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("EntitySetPath".equals(jp.getCurrentName())) { action.setEntitySetPath(jp.nextTextValue()); } else if ("Parameter".equals(jp.getCurrentName())) { jp.nextToken();/* w w w . jav a 2 s . co m*/ action.getParameters().add(jp.readValueAs(ParameterImpl.class)); } else if ("ReturnType".equals(jp.getCurrentName())) { action.setReturnType(parseReturnType(jp, "Action")); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); action.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); } } } return action; }
From source file:org.apache.olingo.client.core.edm.xml.annotation.DynamicAnnotationExpressionDeserializer.java
@Override protected AbstractDynamicAnnotationExpression doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { AbstractDynamicAnnotationExpression expression = null; if ("Not".equals(jp.getCurrentName())) { final NotImpl not = new NotImpl(); jp.nextToken();//from w ww . j av a 2 s . c om for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) { } not.setExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); for (; jp.getCurrentToken() != JsonToken.END_OBJECT || !jp.getCurrentName().equals("Not"); jp .nextToken()) { } expression = not; } else if (TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName()) != null) { final TwoParamsOpDynamicAnnotationExpressionImpl dynExprDoubleParamOp = new TwoParamsOpDynamicAnnotationExpressionImpl(); dynExprDoubleParamOp .setType(TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName())); jp.nextToken(); for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) { } dynExprDoubleParamOp.setLeftExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); dynExprDoubleParamOp.setRightExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); for (; jp.getCurrentToken() != JsonToken.END_OBJECT || !jp.getCurrentName().equals(dynExprDoubleParamOp.getType().name()); jp.nextToken()) { } expression = dynExprDoubleParamOp; } else if (ArrayUtils.contains(EL_OR_ATTR, jp.getCurrentName())) { final AbstractElementOrAttributeExpression elOrAttr = getElementOrAttributeExpressio( jp.getCurrentName()); elOrAttr.setValue(jp.nextTextValue()); expression = elOrAttr; } else if (APPLY.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(ApplyImpl.class); } else if (CAST.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(CastImpl.class); } else if (COLLECTION.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(CollectionImpl.class); } else if (IF.equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); final IfImpl _if = new IfImpl(); _if.setGuard(parseConstOrEnumExpression(jp)); _if.setThen(parseConstOrEnumExpression(jp)); _if.setElse(parseConstOrEnumExpression(jp)); expression = _if; } else if (IS_OF.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(IsOfImpl.class); } else if (LABELED_ELEMENT.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(LabeledElementImpl.class); } else if (NULL.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(NullImpl.class); } else if (RECORD.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(RecordImpl.class); } else if (URL_REF.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(UrlRefImpl.class); } return expression; }
From source file:org.apache.olingo.client.core.edm.xml.ComplexTypeDeserializer.java
@Override protected AbstractComplexType doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final AbstractComplexType complexType = ODataServiceVersion.V30 == version ? new org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl() : new org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { complexType.setName(jp.nextTextValue()); } else if ("Abstract".equals(jp.getCurrentName())) { ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType) .setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("BaseType".equals(jp.getCurrentName())) { ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType) .setBaseType(jp.nextTextValue()); } else if ("OpenType".equals(jp.getCurrentName())) { ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType) .setOpenType(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Property".equals(jp.getCurrentName())) { jp.nextToken();//w w w . j a v a 2 s . c o m if (complexType instanceof org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl) { ((org.apache.olingo.client.core.edm.xml.v3.ComplexTypeImpl) complexType).getProperties() .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v3.PropertyImpl.class)); } else { ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).getProperties() .add(jp.readValueAs(org.apache.olingo.client.core.edm.xml.v4.PropertyImpl.class)); } } else if ("NavigationProperty".equals(jp.getCurrentName())) { jp.nextToken(); ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType) .getNavigationProperties().add(jp.readValueAs( org.apache.olingo.client.core.edm.xml.v4.NavigationPropertyImpl.class)); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); ((org.apache.olingo.client.core.edm.xml.v4.ComplexTypeImpl) complexType).getAnnotations() .add(jp.readValueAs(AnnotationImpl.class)); } } } return complexType; }