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.netflix.hollow.jsonadapter.HollowJsonAdapter.java
private int addObject(JsonParser parser, String typeName) throws IOException { ObjectFieldMapping objectMapping = getObjectFieldMapping(typeName); Boolean passthroughDecoratedTypes = null; JsonToken token = parser.nextToken(); PassthroughWriteRecords rec = null;//from ww w. ja va2 s. c o m String fieldName = null; try { while (token != JsonToken.END_OBJECT) { if (token != JsonToken.FIELD_NAME) { fieldName = parser.getCurrentName(); ObjectMappedFieldPath mappedFieldPath = objectMapping.getMappedFieldPath(fieldName); if (mappedFieldPath != null) { addObjectField(parser, token, mappedFieldPath); } else { if (passthroughDecoratedTypes == null) { passthroughDecoratedTypes = Boolean .valueOf(this.passthroughDecoratedTypes.contains(typeName)); if (passthroughDecoratedTypes.booleanValue()) { rec = getPassthroughWriteRecords(); } } if (passthroughDecoratedTypes.booleanValue()) { addPassthroughField(parser, token, fieldName, rec); } else { skipObjectField(parser, token); } } } token = parser.nextToken(); } } catch (Exception ex) { throw new IOException( "Failed to parse field=" + fieldName + ", schema=" + typeName + ", token=" + token, ex); } if (passthroughDecoratedTypes != null && passthroughDecoratedTypes.booleanValue()) { rec.passthroughRec.setReference("singleValues", stateEngine.add("SingleValuePassthroughMap", rec.singleValuePassthroughMapRec)); rec.passthroughRec.setReference("multiValues", stateEngine.add("MultiValuePassthroughMap", rec.multiValuePassthroughMapRec)); int passthroughOrdinal = stateEngine.add("PassthroughData", rec.passthroughRec); return objectMapping.build(passthroughOrdinal); } return objectMapping.build(-1); }
From source file:com.cedarsoft.serialization.jackson.AbstractJacksonSerializer.java
/** * If the format version override is not null, the type and version field are skipped * @param parser the parser/* w w w . j a v a2s .c om*/ * @param formatVersionOverride the format version override (usually "null") * @return the deserialized object * @throws java.io.IOException if there is an io problem */ @Nonnull protected T deserializeInternal(@Nonnull JsonParser parser, @Nullable Version formatVersionOverride) throws IOException, JsonProcessingException, SerializationException { JacksonParserWrapper parserWrapper = new JacksonParserWrapper(parser); Version version = prepareDeserialization(parserWrapper, formatVersionOverride); T deserialized = deserialize(parser, version); if (isObjectType()) { if (parserWrapper.getCurrentToken() != JsonToken.END_OBJECT) { throw new JsonParseException("No consumed everything " + parserWrapper.getCurrentToken(), parserWrapper.getCurrentLocation()); } } return deserialized; }
From source file:com.microsoft.azure.storage.core.EncryptionData.java
public static void consumeJsonObject(JsonParser parser) throws IOException { JsonUtilities.assertIsStartObjectJsonToken(parser); parser.nextToken();/* w w w .ja v a2 s .c om*/ if (parser.getCurrentToken() != JsonToken.END_OBJECT) { consumeJsonObject(parser); } }
From source file:org.emfjson.jackson.streaming.StreamReader.java
@SuppressWarnings("unchecked") protected JsonToken parseEntry(JsonParser parser, EReference reference, EObject owner) throws IOException { EList<EObject> values = null;/* www.jav a 2 s .c o m*/ if (reference.isMany()) { values = (EList<EObject>) owner.eGet(reference); } while (parser.nextToken() != JsonToken.END_OBJECT) { final String field = parser.getCurrentName(); final String value = parser.nextTextValue(); if (reference.isMany() && values != null) { values.add(createEntry(field, value)); } else { owner.eSet(reference, createEntry(field, value)); } } return parser.getCurrentToken(); }
From source file:org.seedstack.seed.core.internal.data.DataManagerImpl.java
@Override public void importData(InputStream inputStream, String acceptGroup, String acceptName, boolean clear) { Set<DataImporter<Object>> usedDataImporters = new HashSet<>(); try {/*from www . j av a2 s . c om*/ ParsingState state = ParsingState.START; String group = null; String name = null; JsonParser jsonParser = this.jsonFactory .createParser(new InputStreamReader(inputStream, Charset.forName(UTF_8))); JsonToken jsonToken = jsonParser.nextToken(); while (jsonToken != null) { switch (state) { case START: if (jsonToken == JsonToken.START_ARRAY) { state = ParsingState.DEFINITION_START; } else { throwParsingError(jsonParser.getCurrentLocation(), "start array expected"); } break; case DEFINITION_START: if (jsonToken == JsonToken.START_OBJECT) { state = ParsingState.DEFINITION_GROUP; } else { throwParsingError(jsonParser.getCurrentLocation(), "start object expected"); } break; case DEFINITION_GROUP: if (jsonToken == JsonToken.FIELD_NAME && GROUP.equals(jsonParser.getCurrentName())) { group = jsonParser.nextTextValue(); state = ParsingState.DEFINITION_NAME; } else { throwParsingError(jsonParser.getCurrentLocation(), "group field expected"); } break; case DEFINITION_NAME: if (jsonToken == JsonToken.FIELD_NAME && NAME.equals(jsonParser.getCurrentName())) { name = jsonParser.nextTextValue(); state = ParsingState.DEFINITION_ITEMS; } else { throwParsingError(jsonParser.getCurrentLocation(), "name field expected"); } break; case DEFINITION_ITEMS: if (jsonToken == JsonToken.FIELD_NAME && ITEMS.equals(jsonParser.getCurrentName())) { usedDataImporters.add(consumeItems(jsonParser, group, name, acceptGroup, acceptName)); state = ParsingState.DEFINITION_END; } else { throwParsingError(jsonParser.getCurrentLocation(), "items field expected"); } break; case DEFINITION_END: if (jsonToken == JsonToken.END_OBJECT) { group = null; name = null; state = ParsingState.END; } else { throwParsingError(jsonParser.getCurrentLocation(), "end object expected"); } break; case END: if (jsonToken == JsonToken.START_OBJECT) { state = ParsingState.DEFINITION_GROUP; } else if (jsonToken == JsonToken.END_ARRAY) { state = ParsingState.START; } else { throwParsingError(jsonParser.getCurrentLocation(), "start object or end array expected"); } break; default: throwParsingError(jsonParser.getCurrentLocation(), "unexpected parser state"); } jsonToken = jsonParser.nextToken(); } } catch (Exception e1) { for (DataImporter<Object> usedDataImporter : usedDataImporters) { try { usedDataImporter.rollback(); } catch (Exception e2) { e2.initCause(e1); throw SeedException.wrap(e2, DataErrorCode.FAILED_TO_ROLLBACK_IMPORT).put(IMPORTER_CLASS, usedDataImporter.getClass().getName()); } } throw SeedException.wrap(e1, DataErrorCode.IMPORT_FAILED); } for (DataImporter<Object> usedDataImporter : usedDataImporters) { try { usedDataImporter.commit(clear); } catch (Exception e) { throw SeedException.wrap(e, DataErrorCode.FAILED_TO_COMMIT_IMPORT).put(IMPORTER_CLASS, usedDataImporter.getClass().getName()); } } }
From source file:org.messic.server.api.tagwizard.discogs.DiscogsTAGWizardPlugin.java
private Album getAlbum(String id) { String baseURL = "http://api.discogs.com/releases/" + id; try {/*from w ww . j ava 2 s .co m*/ URL url = new URL(baseURL); Proxy proxy = getProxy(); URLConnection uc = (proxy != null ? url.openConnection(proxy) : url.openConnection()); uc.setRequestProperty("User-Agent", "Messic/1.0 +http://spheras.github.io/messic/"); Album album = new Album(); album.name = ""; album.author = ""; album.comments = "Info obtained by Discogs provider (http://www.discogs.com/)"; album.year = 1900; album.genre = ""; JsonFactory jsonFactory = new JsonFactory(); // or, for data binding, JsonParser jParser = jsonFactory.createParser(uc.getInputStream()); while (jParser.nextToken() != null) { String fieldname = jParser.getCurrentName(); if ("title".equals(fieldname)) { jParser.nextToken(); album.name = jParser.getText(); } if ("year".equals(fieldname)) { jParser.nextToken(); try { album.year = Integer.valueOf(jParser.getText()); } catch (Exception e) { album.year = 0; } } if ("notes".equals(fieldname)) { jParser.nextToken(); album.comments = jParser.getText(); } if ("genres".equals(fieldname)) { jParser.nextToken(); jParser.nextToken(); album.genre = jParser.getText(); do { jParser.nextToken(); } while (!"genres".equals(jParser.getCurrentName())); } if ("artists".equals(fieldname)) { jParser.nextToken(); while (!"name".equals(jParser.getCurrentName())) { jParser.nextToken(); } jParser.nextToken(); album.author = jParser.getText(); do { jParser.nextToken(); } while (!"artists".equals(jParser.getCurrentName())); } if ("tracklist".equals(fieldname)) { album.songs = new ArrayList<Song>(); do { Song newsong = new Song(); int tracknumber = 1; while (jParser.nextToken() != JsonToken.END_OBJECT) { String trackfieldname = jParser.getCurrentName(); if ("extraartists".equals(trackfieldname)) { do { while (jParser.nextToken() != JsonToken.END_OBJECT) { } jParser.nextToken(); } while (!"extraartists".equals(jParser.getCurrentName())); } if ("position".equals(trackfieldname)) { jParser.nextToken(); try { newsong.track = Integer.valueOf(jParser.getText()); } catch (Exception e) { newsong.track = tracknumber; } tracknumber++; } if ("title".equals(trackfieldname)) { jParser.nextToken(); newsong.name = jParser.getText(); } } album.songs.add(newsong); jParser.nextToken(); } while (!"tracklist".equals(jParser.getCurrentName())); jParser.nextToken(); } } return album; } catch (Exception e) { log.error("failed!", e); } return null; }
From source file:com.cinnober.msgcodec.json.TypeScannerJsonParser.java
private void parseValuesUntil(JsonToken end) throws IOException { for (;;) {/* w w w . ja v a2 s. com*/ JsonToken token = p.nextToken(); if (token == null) { throw new DecodeException("Unexpected JSON token null"); } if (token == end) { break; } else { if (end == JsonToken.END_OBJECT) { parseField(); } parseValue(); } } }
From source file:com.boundary.zoocreeper.Restore.java
private static ACL readACL(JsonParser jp) throws IOException { expectCurrentToken(jp, JsonToken.START_OBJECT); String scheme = null;//from www. j a va 2s.c o m String id = null; int perms = -1; final Set<String> seenFields = Sets.newHashSet(); while (jp.nextToken() != JsonToken.END_OBJECT) { jp.nextValue(); final String fieldName = jp.getCurrentName(); seenFields.add(fieldName); if (Backup.FIELD_ACL_SCHEME.equals(fieldName)) { scheme = jp.getValueAsString(); } else if (Backup.FIELD_ACL_ID.equals(fieldName)) { id = jp.getValueAsString(); } else if (Backup.FIELD_ACL_PERMS.equals(fieldName)) { perms = jp.getIntValue(); } else { throw new IOException("Unexpected field: " + fieldName); } } if (!seenFields.containsAll(REQUIRED_ACL_FIELDS)) { throw new IOException("Missing required ACL fields: " + REQUIRED_ACL_FIELDS); } final Id zkId; if (Ids.ANYONE_ID_UNSAFE.getScheme().equals(scheme) && Ids.ANYONE_ID_UNSAFE.getId().equals(id)) { zkId = Ids.ANYONE_ID_UNSAFE; } else { zkId = new Id(scheme, id); } return new ACL(perms, zkId); }
From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromJsonStream.java
private void readFileMeta() throws Exception { jp.nextToken();/*from w w w . j a v a 2s .c o m*/ while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldName = jp.getCurrentName(); jp.nextToken(); // Move to value. switch (fieldName) { case "version": version = jp.getValueAsString(); task.log().debug("JSON version: %s", version); break; case "date": break; default: task.log().warn("Unknown .oimeta fieldname %s", fieldName); } } jp.nextToken(); }
From source file:io.apiman.manager.api.exportimport.json.JsonImportReader.java
public void readApis() throws Exception { current = nextToken();//from w w w . j a va 2s. c om if (current == JsonToken.END_ARRAY) { return; } while (nextToken() != JsonToken.END_ARRAY) { // Traverse each api definition while (nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentName().equals(ApiBean.class.getSimpleName())) { current = nextToken(); ApiBean apiBean = jp.readValueAs(ApiBean.class); dispatcher.api(apiBean); } else { OrgElementsEnum fieldName = OrgElementsEnum.valueOf(jp.getCurrentName()); current = nextToken(); switch (fieldName) { case Versions: readApiVersions(); break; default: throw new RuntimeException("Unhandled entity " + fieldName + " with token " + current); } } } } }