List of usage examples for com.fasterxml.jackson.core JsonParser getCurrentName
public abstract String getCurrentName() throws IOException, JsonParseException;
From source file:com.github.heuermh.ensemblrestclient.JacksonLookupConverter.java
static Lookup parseLookup(final JsonFactory jsonFactory, final InputStream inputStream) throws IOException { JsonParser parser = null; try {//from w ww . j a va 2s .c o m parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String species = null; String type = null; String database = null; String locationName = null; String coordinateSystem = "chromosome"; // reasonable default? int start = -1; int end = -1; int strand = -1; while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("species".equals(field)) { species = parser.getText(); } else if ("object_type".equals(field)) { type = parser.getText(); } else if ("db_type".equals(field)) { database = parser.getText(); } else if ("seq_region_name".equals(field)) { locationName = parser.getText(); } else if ("start".equals(field)) { start = Integer.parseInt(parser.getText()); } else if ("end".equals(field)) { end = Integer.parseInt(parser.getText()); } else if ("strand".equals(field)) { strand = Integer.parseInt(parser.getText()); } } return new Lookup(id, species, type, database, new Location(locationName, coordinateSystem, start, end, strand)); } finally { try { inputStream.close(); } catch (Exception e) { // ignored } try { parser.close(); } catch (Exception e) { // ignored } } }
From source file:com.github.heuermh.ensemblrestclient.JacksonArchivedSequenceConverter.java
static ArchivedSequence parseArchivedSequence(final JsonFactory jsonFactory, final InputStream inputStream) throws IOException { JsonParser parser = null; try {//from w ww .ja v a 2 s . c om parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String type = null; String assembly = null; String release = null; String version = null; String latest = null; String peptide = null; boolean current = false; List<String> possibleReplacement = new ArrayList<String>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("type".equals(field)) { type = parser.getText(); } else if ("assembly".equals(field)) { assembly = parser.getText(); } else if ("release".equals(field)) { release = parser.getText(); } else if ("version".equals(field)) { version = parser.getText(); } else if ("latest".equals(field)) { latest = parser.getText(); } else if ("peptide".equals(field)) { peptide = parser.getText(); } else if ("is_current".equals(field)) { current = (Integer.parseInt(parser.getText()) > 0); } else if ("possible_replacement".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { possibleReplacement.add(parser.getText()); } } } return new ArchivedSequence(id, type, assembly, release, version, latest, peptide, current, possibleReplacement.toArray(new String[possibleReplacement.size()])); } finally { try { inputStream.close(); } catch (Exception e) { // ignored } try { parser.close(); } catch (Exception e) { // ignored } } }
From source file:org.helm.notation2.wsadapter.MonomerWSLoader.java
/** * Private routine to deserialize JSON containing monomer categorization data. * This is done manually to give more freedom regarding data returned by the * webservice./* w w w .j a v a2 s .c o m*/ * * @param parser the JSONParser containing JSONData. * @return List containing the monomer categorization * * @throws JsonParseException * @throws IOException */ private static List<CategorizedMonomer> deserializeEditorCategorizationConfig(JsonParser parser) throws JsonParseException, IOException { List<CategorizedMonomer> config = new LinkedList<CategorizedMonomer>(); CategorizedMonomer currentMonomer = null; parser.nextToken(); while (parser.hasCurrentToken()) { String fieldName = parser.getCurrentName(); JsonToken token = parser.getCurrentToken(); if (JsonToken.START_OBJECT.equals(token)) { currentMonomer = new CategorizedMonomer(); } else if (JsonToken.END_OBJECT.equals(token)) { config.add(currentMonomer); } if (fieldName != null) { switch (fieldName) { // id is first field case "monomerID": parser.nextToken(); currentMonomer.setMonomerID(parser.getText()); break; case "monomerName": parser.nextToken(); currentMonomer.setMonomerName(parser.getText()); break; case "naturalAnalogon": parser.nextToken(); currentMonomer.setNaturalAnalogon(parser.getText()); break; case "monomerType": parser.nextToken(); currentMonomer.setMonomerType(parser.getText()); break; case "polymerType": parser.nextToken(); currentMonomer.setPolymerType(parser.getText()); break; case "category": parser.nextToken(); currentMonomer.setCategory(parser.getText()); break; case "shape": parser.nextToken(); currentMonomer.setShape(parser.getText()); break; case "fontColor": parser.nextToken(); currentMonomer.setFontColor(parser.getText()); break; case "backgroundColor": parser.nextToken(); currentMonomer.setBackgroundColor(parser.getText()); break; default: break; } } parser.nextToken(); } return config; }
From source file:org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.java
static List<Node> readHosts(HttpEntity entity, Scheme scheme, JsonFactory jsonFactory) throws IOException { try (InputStream inputStream = entity.getContent()) { JsonParser parser = jsonFactory.createParser(inputStream); if (parser.nextToken() != JsonToken.START_OBJECT) { throw new IOException("expected data to start with an object"); }//from w w w.j a va 2 s . c o m List<Node> nodes = new ArrayList<>(); while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.START_OBJECT) { if ("nodes".equals(parser.getCurrentName())) { while (parser.nextToken() != JsonToken.END_OBJECT) { JsonToken token = parser.nextToken(); assert token == JsonToken.START_OBJECT; String nodeId = parser.getCurrentName(); Node node = readNode(nodeId, parser, scheme); if (node != null) { nodes.add(node); } } } else { parser.skipChildren(); } } } return nodes; } }
From source file:com.ntsync.shared.RequestGenerator.java
private static Map<Long, String> extractNewIdList(JsonParser jp) throws IOException { Map<Long, String> newIdMap = new HashMap<Long, String>(); while (jp.nextToken() != JsonToken.END_OBJECT) { String clientIdStr = jp.getCurrentName(); if (jp.nextToken() == null) { break; }/*from w w w.j a va 2 s .co m*/ String serverRowId = jp.getValueAsString(); try { Long clientRowId = Long.valueOf(clientIdStr); newIdMap.put(clientRowId, serverRowId); } catch (NumberFormatException ex) { LOG.warn("Invalid ID from server. Id:" + clientIdStr + " ServerId:" + serverRowId, ex); } } return newIdMap; }
From source file:com.ntsync.shared.RequestGenerator.java
/** * Parse a JSON-Object with "Server/Config/*" which the Restrictions * //from ww w . j a v a 2 s . co m * @param is * @return * @throws IOException */ public static Restrictions parseRestr(InputStream is) throws IOException { JsonParser jp = getJsonFactory().createParser(is); jp.nextToken(); Restrictions restr = null; while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); // move to value, or START_OBJECT/START_ARRAY if (jp.nextToken() == null) { break; } if (SERVER_FIELD_NAME.equals(fieldname)) { while (jp.nextToken() != JsonToken.END_OBJECT) { String serverField = jp.getCurrentName(); if (jp.nextToken() == null) { break; } if (RequestGenerator.TAG_SERVER_CONFIG.equals(serverField)) { restr = parseRestr(jp); } } } } return restr; }
From source file:com.github.heuermh.ensemblrestclient.JacksonOverlapConverter.java
static List<Variation> parseOverlap(final JsonFactory jsonFactory, final InputStream inputStream) throws IOException { JsonParser parser = null; try {//w ww.j a va2 s .co m parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reference = null; List<String> alternateAlleles = new ArrayList<String>(); String locationName = null; String coordinateSystem = "chromosome"; int start = -1; int end = -1; int strand = -1; List<Variation> variationFeatures = new ArrayList<Variation>(); while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("seq_region_name".equals(field)) { locationName = parser.getText(); } else if ("start".equals(field)) { start = Integer.parseInt(parser.getText()); } else if ("end".equals(field)) { end = Integer.parseInt(parser.getText()); } else if ("strand".equals(field)) { strand = Integer.parseInt(parser.getText()); } else if ("alt_alleles".equals(field)) { int index = 0; while (parser.nextToken() != JsonToken.END_ARRAY) { if (index == 0) { reference = parser.getText(); } else if (index == 1) { alternateAlleles.add(parser.getText()); } index++; } } } variationFeatures.add(new Variation(id, reference, alternateAlleles, new Location(locationName, coordinateSystem, start, end, strand))); id = null; reference = null; alternateAlleles.clear(); locationName = null; start = -1; end = -1; strand = -1; } return variationFeatures; } finally { try { inputStream.close(); } catch (Exception e) { // ignored } try { parser.close(); } catch (Exception e) { // ignored } } }
From source file:com.github.heuermh.ensemblrestclient.JacksonVariationConverter.java
static Variation parseVariation(final JsonFactory jsonFactory, final InputStream inputStream) throws IOException { JsonParser parser = null; try {//from w w w .j a v a2 s . co m parser = jsonFactory.createParser(inputStream); parser.nextToken(); String identifier = null; String referenceAllele = null; List<String> alternateAlleles = new ArrayList<String>(); String locationName = null; String coordinateSystem = "chromosome"; int start = -1; int end = -1; int strand = -1; while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("name".equals(field)) { identifier = parser.getText(); } else if ("mappings".equals(field)) { // todo: will only catch last mapping while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String mappingsField = parser.getCurrentName(); parser.nextToken(); if ("seq_region_name".equals(mappingsField)) { locationName = parser.getText(); } else if ("start".equals(mappingsField)) { start = Integer.parseInt(parser.getText()); } else if ("end".equals(mappingsField)) { end = Integer.parseInt(parser.getText()); } else if ("strand".equals(mappingsField)) { strand = Integer.parseInt(parser.getText()); } else if ("allele_string".equals(mappingsField)) { String[] tokens = parser.getText().split("/"); // todo: check ref here against ancestral_allele referenceAllele = tokens[0]; for (int i = 1; i < tokens.length; i++) { alternateAlleles.add(tokens[i]); } } } } } else if ("synonyms".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { // ignore } } else if ("evidence".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { // ignore } } } return new Variation(identifier, referenceAllele, alternateAlleles, new Location(locationName, coordinateSystem, start, end, strand)); } finally { try { inputStream.close(); } catch (Exception e) { // ignored } try { parser.close(); } catch (Exception e) { // ignored } } }
From source file:com.ntsync.shared.RequestGenerator.java
private static Restrictions parseRestr(JsonParser jp) throws IOException { int maxContacts = Integer.MAX_VALUE; int maxGroups = Integer.MAX_VALUE; boolean photoSyncSupported = false; Date validUntil = null;/*from w ww. j a v a2s . co m*/ while (jp.nextToken() != JsonToken.END_OBJECT) { String configName = jp.getCurrentName(); if (jp.nextToken() == null) { break; } if (PARAM_IS_PHOTO_SYNC_ENABLED.equals(configName)) { photoSyncSupported = jp.getBooleanValue(); } else if (PARAM_MAX_CONTACTS.equals(configName)) { maxContacts = jp.getIntValue(); } else if (PARAM_MAX_GROUPS.equals(configName)) { maxGroups = jp.getIntValue(); } else if (PARAM_VALID_UNTIL.equals(configName)) { validUntil = new Date(jp.getLongValue()); } } return new Restrictions(maxContacts, maxGroups, photoSyncSupported, validUntil); }
From source file:io.syndesis.jsondb.impl.JsonRecordSupport.java
public static void jsonStreamToRecords(JsonParser jp, String path, Consumer<JsonRecord> consumer) throws IOException { boolean inArray = false; int arrayIndex = 0; while (true) { JsonToken nextToken = jp.nextToken(); String currentPath = path; if (nextToken == FIELD_NAME) { if (inArray) { currentPath = path + toArrayIndexPath(arrayIndex) + "/"; }/* w w w . j av a2 s.c o m*/ jsonStreamToRecords(jp, currentPath + validateKey(jp.getCurrentName()) + "/", consumer); } else if (nextToken == VALUE_NULL) { if (inArray) { currentPath = path + toArrayIndexPath(arrayIndex) + "/"; } consumer.accept(JsonRecord.of(currentPath, "", nextToken.id())); if (inArray) { arrayIndex++; } else { return; } } else if (nextToken.isScalarValue()) { if (inArray) { currentPath = path + toArrayIndexPath(arrayIndex) + "/"; } consumer.accept(JsonRecord.of(currentPath, jp.getValueAsString(), nextToken.id())); if (inArray) { arrayIndex++; } else { return; } } else if (nextToken == END_OBJECT) { if (inArray) { arrayIndex++; } else { return; } } else if (nextToken == START_ARRAY) { inArray = true; } else if (nextToken == END_ARRAY) { return; } } }