List of usage examples for com.fasterxml.jackson.core JsonParser getCurrentName
public abstract String getCurrentName() throws IOException, JsonParseException;
From source file:org.elasticsearch.client.sniff.ElasticsearchHostsSniffer.java
private static HttpHost readHost(String nodeId, JsonParser parser, Scheme scheme) throws IOException { HttpHost httpHost = null;//from w ww . ja v a 2 s.c om String fieldName = null; while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.FIELD_NAME) { fieldName = parser.getCurrentName(); } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { if ("http".equals(fieldName)) { while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.VALUE_STRING && "publish_address".equals(parser.getCurrentName())) { URI boundAddressAsURI = URI.create(scheme + "://" + parser.getValueAsString()); httpHost = new HttpHost(boundAddressAsURI.getHost(), boundAddressAsURI.getPort(), boundAddressAsURI.getScheme()); } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { parser.skipChildren(); } } } else { parser.skipChildren(); } } } //http section is not present if http is not enabled on the node, ignore such nodes if (httpHost == null) { logger.debug("skipping node [" + nodeId + "] with http disabled"); return null; } return httpHost; }
From source file:com.microsoft.azure.storage.core.WrappedContentKey.java
public static WrappedContentKey deserialize(JsonParser parser) throws JsonParseException, IOException { JsonUtilities.assertIsStartObjectJsonToken(parser); parser.nextToken();/* w w w . j a va 2 s. co m*/ WrappedContentKey wrappedContentKey = new WrappedContentKey(); while (parser.getCurrentToken() != JsonToken.END_OBJECT) { String name = parser.getCurrentName(); parser.nextToken(); if (name.equals("KeyId")) { wrappedContentKey.setKeyId(parser.getValueAsString()); } else if (name.equals("EncryptedKey")) { wrappedContentKey.setEncryptedKey(parser.getBinaryValue()); } else if (name.equals("Algorithm")) { wrappedContentKey.setAlgorithm(parser.getValueAsString()); } parser.nextToken(); } JsonUtilities.assertIsEndObjectJsonToken(parser); return wrappedContentKey; }
From source file:io.seldon.spark.actions.JobUtils.java
public static ActionData getActionDataFromActionLogLine(String actionLogLine) { ActionData actionData = new ActionData(); String[] parts = actionLogLine.split("\\s+", 3); String json = parts[2];// w w w . j a v a 2 s . co m actionData.timestamp_utc = parts[0]; JsonFactory jsonF = new JsonFactory(); try { JsonParser jp = jsonF.createParser(json); if (jp.nextToken() != JsonToken.START_OBJECT) { throw new IOException("Expected data to start with an Object"); } while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldName = jp.getCurrentName(); // Let's move to value jp.nextToken(); if (fieldName.equals("client")) { actionData.client = jp.getText(); } else if (fieldName.equals("client_userid")) { actionData.client_userid = jp.getText(); } else if (fieldName.equals("userid")) { actionData.userid = jp.getValueAsInt(); } else if (fieldName.equals("itemid")) { actionData.itemid = jp.getValueAsInt(); } else if (fieldName.equals("client_itemid")) { actionData.client_itemid = jp.getText(); } else if (fieldName.equals("rectag")) { actionData.rectag = jp.getText(); } else if (fieldName.equals("type")) { actionData.type = jp.getValueAsInt(); } else if (fieldName.equals("value")) { actionData.value = jp.getValueAsDouble(); } } jp.close(); } catch (JsonParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return actionData; }
From source file:org.n52.movingcode.runtime.processors.config.ProcessorConfig.java
/** * Properties reader/*from w w w. ja va 2 s . c o m*/ * * @return */ private static final HashMap<String, ProcessorDescription> readProperties() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream is = classLoader.getResourceAsStream(configFile); HashMap<String, ProcessorDescription> processorMap = new HashMap<String, ProcessorDescription>(); JsonFactory f = new JsonFactory(); JsonParser jp; try { jp = f.createParser(is); jp.nextToken(); // will return JsonToken.START_OBJECT while (jp.nextToken() != END_OBJECT) { String field = jp.getCurrentName(); if (field.equalsIgnoreCase(KEY_PROCESSORS)) { // get next token, make sure it is the beginning of an array if (jp.nextToken() != START_ARRAY) { break; } while (jp.nextToken() != END_ARRAY) { // do the parsing if (jp.getCurrentToken() == START_OBJECT) { ProcessorDescription p = parseProcessorJSON(jp); // only add those processor that have a valid ID if (p.getId() != null) { processorMap.put(p.getId(), p); } } } } else { if (field.equalsIgnoreCase(KEY_DEFAULTS)) { // parse defaults ProcessorDescription p = parseProcessorJSON(jp); p.setId(DEFAULT_PROCESSOR_CONFIG_ID); processorMap.put(p.getId(), p); } } } } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return processorMap; }
From source file:com.ntsync.shared.ContactGroup.java
/** * Creates and returns an instance of the RawContact from encrypted data * /* www. java 2s . c o m*/ * */ public static ContactGroup valueOf(String rowId, Map<Byte, ByteBuffer> values, Key privateKey) throws InvalidKeyException { try { String sourceId = null; Long rawId = null; if (values.containsKey(GroupConstants.SERVERROW_ID)) { sourceId = readRawString(values.get(GroupConstants.SERVERROW_ID)); } if (sourceId == null || !sourceId.equals(rowId)) { // If ServerContactId is different, then rowId is the clientId rawId = Long.parseLong(rowId); } if (sourceId == null && rawId < 0) { throw new IllegalArgumentException("Missing RowId in data"); } AEADBlockCipher cipher = CryptoHelper.getCipher(); final boolean deleted = values.containsKey(GroupConstants.DELETED); final String textData = CryptoHelper.decodeStringValue(GroupConstants.TEXTDATA, values, cipher, privateKey); if (textData == null && !deleted) { LOG.error("No textdata found for row with Id:" + rowId); return null; } String title = null; String notes = null; if (!isEmpty(textData)) { JsonFactory fac = new JsonFactory(); JsonParser jp = fac.createParser(textData); jp.nextToken(); while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); // move to value, or START_OBJECT/START_ARRAY jp.nextToken(); if (GroupConstants.TITLE.equals(fieldname)) { title = jp.getValueAsString(); } else if (GroupConstants.NOTES.equals(fieldname)) { notes = jp.getValueAsString(); } else { LOG.error("Unrecognized field for row with Id:" + rowId + " Fieldname:" + fieldname); } } jp.close(); } String modStr = readRawString(values.get(GroupConstants.MODIFIED)); Date lastModified = null; if (!isEmpty(modStr)) { lastModified = new Date(Long.parseLong(modStr)); } return new ContactGroup(rawId, sourceId, title, notes, deleted, lastModified, -1); } catch (InvalidCipherTextException ex) { throw new InvalidKeyException("Invalid key detected.", ex); } catch (final Exception ex) { LOG.info("Error parsing contactgroup data. Reason:" + ex.toString(), ex); } return null; }
From source file:com.netflix.hollow.jsonadapter.util.JsonUtil.java
private static void print(JsonParser parser, JsonToken token, int index, PrintStream out) throws Exception { if (index == 0) System.out.println("\n\n -----"); try {/* w w w. ja v a 2 s . c o m*/ while (token != null && token != JsonToken.END_OBJECT) { switch (token) { case START_ARRAY: print(index, String.format("fieldname=%s, token=%s", parser.getCurrentName(), token), out); print(parser, parser.nextToken(), index + 1, out); break; case START_OBJECT: print(index, String.format("fieldname=%s, token=%s", parser.getCurrentName(), token), out); print(parser, parser.nextToken(), index + 1, out); break; case VALUE_NUMBER_INT: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getLongValue()), out); break; case VALUE_NUMBER_FLOAT: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getDoubleValue()), out); break; case VALUE_NULL: print(index, String.format("fieldname=%s, token=%s, value=NULL", parser.getCurrentName(), token), out); break; case VALUE_STRING: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getValueAsString()), out); break; case VALUE_FALSE: case VALUE_TRUE: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getBooleanValue()), out); break; case FIELD_NAME: //print(index, String.format("fieldname=%s, token=%s", parser.getCurrentName(), token)); break; case END_ARRAY: case END_OBJECT: index--; break; default: } token = parser.nextToken(); } } catch (Exception ex) { ex.printStackTrace(); throw ex; } }
From source file:ai.susi.geo.GeoJsonReader.java
private static Map<String, String> parseMap(JsonParser parser) throws JsonParseException, IOException { Map<String, String> map = new HashMap<>(); JsonToken token = parser.nextToken(); if (!JsonToken.START_OBJECT.equals(token)) return map; while (!parser.isClosed() && (token = parser.nextToken()) != null && token != JsonToken.END_OBJECT) { String name = parser.getCurrentName(); token = parser.nextToken();//from w w w. j ava2 s. c om String value = parser.getText(); map.put(name.toLowerCase(), value); } return map; }
From source file:eu.project.ttc.readers.TermSuiteJsonCasDeserializer.java
private static void FillFixedExpressions(JsonParser parser, JsonToken token, FixedExpression fe, CAS cas) throws IOException { if (token.equals(JsonToken.FIELD_NAME)) { switch (parser.getCurrentName()) { case F_BEGIN: fe.setBegin(parser.nextIntValue(0)); break; case F_END: fe.setEnd(parser.nextIntValue(0)); break; }//from w w w.j a v a2s . com } }
From source file:eu.project.ttc.readers.TermSuiteJsonCasDeserializer.java
private static void fillSdi(JsonParser parser, JsonToken token, SourceDocumentInformation sdi) throws IOException { if (token.equals(JsonToken.FIELD_NAME)) { switch (parser.getCurrentName()) { case F_URI: sdi.setUri(parser.nextTextValue()); break; case F_OFFSET_IN_SOURCE: sdi.setOffsetInSource(parser.nextIntValue(0)); break; case F_DOCUMENT_INDEX: sdi.setDocumentIndex(parser.nextIntValue(0)); break; case F_NB_DOCUMENTS: sdi.setNbDocuments(parser.nextIntValue(0)); break; case F_DOCUMENT_SIZE: sdi.setDocumentSize(parser.nextIntValue(0)); break; case F_CUMULATED_DOCUMENT_SIZE: sdi.setCumulatedDocumentSize(parser.nextLongValue(0)); break; case F_CORPUS_SIZE: sdi.setCorpusSize(parser.nextLongValue(0)); break; case F_LAST_SEGMENT: sdi.setLastSegment(parser.nextBooleanValue()); break; case F_BEGIN: sdi.setBegin(parser.nextIntValue(0)); break; case F_END: sdi.setEnd(parser.nextIntValue(0)); break; }/*from ww w .j a va 2 s . c om*/ } }
From source file:com.microsoft.azure.storage.core.EncryptionData.java
public static EncryptionData deserialize(JsonParser parser) throws JsonParseException, IOException { JsonUtilities.assertIsStartObjectJsonToken(parser); parser.nextToken();//w ww.j ava 2s.c om EncryptionData data = new EncryptionData(); while (parser.getCurrentToken() != JsonToken.END_OBJECT) { String name = parser.getCurrentName(); parser.nextToken(); if (name.equals(Constants.EncryptionConstants.WRAPPED_CONTENT_KEY)) { data.setWrappedContentKey(WrappedContentKey.deserialize(parser)); } else if (name.equals(Constants.EncryptionConstants.ENCRYPTION_AGENT)) { data.setEncryptionAgent(EncryptionAgent.deserialize(parser)); } else if (name.equals(Constants.EncryptionConstants.CONTENT_ENCRYPTION_IV)) { data.setContentEncryptionIV(parser.getBinaryValue()); } else if (name.equals(Constants.EncryptionConstants.KEY_WRAPPING_METADATA)) { data.setKeyWrappingMetadata(deserializeKeyWrappingMetadata(parser)); } else { consumeJsonObject(parser); } parser.nextToken(); } JsonUtilities.assertIsEndObjectJsonToken(parser); return data; }