Java Code Examples for com.fasterxml.jackson.core.JsonParser#getValueAsString()
The following examples show how to use
com.fasterxml.jackson.core.JsonParser#getValueAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SplitSerDe.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
@Override protected Split doDeserialize(JsonParser jparser, DeserializationContext ctxt) throws IOException { assertFieldName(jparser, SPILL_LOCATION_FIELD); SpillLocation spillLocation = spillLocationDeserializer.deserialize(jparser, ctxt); assertFieldName(jparser, ENCRYPTION_KEY_FIELD); EncryptionKey encryptionKey = encryptionKeyDeserializer.deserialize(jparser, ctxt); assertFieldName(jparser, PROPERTIES_FIELD); validateObjectStart(jparser.nextToken()); ImmutableMap.Builder<String, String> propertiesMap = ImmutableMap.builder(); while (jparser.nextToken() != JsonToken.END_OBJECT) { String key = jparser.getValueAsString(); jparser.nextToken(); String value = jparser.getValueAsString(); propertiesMap.put(key, value); } return new Split(spillLocation, encryptionKey, propertiesMap.build()); }
Example 2
Source File: EthBlock.java From web3j with Apache License 2.0 | 6 votes |
@Override public List<TransactionResult> deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { List<TransactionResult> transactionResults = new ArrayList<>(); JsonToken nextToken = jsonParser.nextToken(); if (nextToken == JsonToken.START_OBJECT) { Iterator<TransactionObject> transactionObjectIterator = objectReader.readValues(jsonParser, TransactionObject.class); while (transactionObjectIterator.hasNext()) { transactionResults.add(transactionObjectIterator.next()); } } else if (nextToken == JsonToken.VALUE_STRING) { jsonParser.getValueAsString(); Iterator<TransactionHash> transactionHashIterator = objectReader.readValues(jsonParser, TransactionHash.class); while (transactionHashIterator.hasNext()) { transactionResults.add(transactionHashIterator.next()); } } return transactionResults; }
Example 3
Source File: BcosLog.java From web3sdk with Apache License 2.0 | 6 votes |
@Override public List<LogResult> deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { List<LogResult> logResults = new ArrayList<>(); JsonToken nextToken = jsonParser.nextToken(); if (nextToken == JsonToken.START_OBJECT) { Iterator<LogObject> logObjectIterator = objectReader.readValues(jsonParser, LogObject.class); while (logObjectIterator.hasNext()) { logResults.add(logObjectIterator.next()); } } else if (nextToken == JsonToken.VALUE_STRING) { jsonParser.getValueAsString(); Iterator<Hash> transactionHashIterator = objectReader.readValues(jsonParser, Hash.class); while (transactionHashIterator.hasNext()) { logResults.add(transactionHashIterator.next()); } } return logResults; }
Example 4
Source File: PlatonLog.java From client-sdk-java with Apache License 2.0 | 6 votes |
@Override public List<LogResult> deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { List<LogResult> logResults = new ArrayList<>(); JsonToken nextToken = jsonParser.nextToken(); if (nextToken == JsonToken.START_OBJECT) { Iterator<LogObject> logObjectIterator = objectReader.readValues(jsonParser, LogObject.class); while (logObjectIterator.hasNext()) { logResults.add(logObjectIterator.next()); } } else if (nextToken == JsonToken.VALUE_STRING) { jsonParser.getValueAsString(); Iterator<Hash> transactionHashIterator = objectReader.readValues(jsonParser, Hash.class); while (transactionHashIterator.hasNext()) { logResults.add(transactionHashIterator.next()); } } return logResults; }
Example 5
Source File: DateTimeDeserializer.java From archie with Apache License 2.0 | 5 votes |
@Override public TemporalAccessor deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { String valueAsString = p.getValueAsString(); if(valueAsString == null) { return null; } return TemporalConstraintParser.parseDateTimeValue(valueAsString); }
Example 6
Source File: DurationDeserializer.java From archie with Apache License 2.0 | 5 votes |
@Override public TemporalAmount deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { String valueAsString = p.getValueAsString(); if(valueAsString == null) { return null; } return TemporalConstraintParser.parseDurationValue(valueAsString); }
Example 7
Source File: ObjectMapperFactory.java From james-project with Apache License 2.0 | 5 votes |
@Override public Rights.Right deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { String nodeValue = p.getValueAsString(); Preconditions.checkArgument(nodeValue.length() == 1, "Rights should be represented as single value characters"); return Rights.Right.forChar(nodeValue.charAt(0)); }
Example 8
Source File: ECKeyDeserializer.java From consensusj with Apache License 2.0 | 5 votes |
@Override public ECKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken token = p.getCurrentToken(); switch (token) { case VALUE_STRING: try { return DumpedPrivateKey.fromBase58(null, p.getValueAsString()).getKey(); } catch (AddressFormatException e) { throw new InvalidFormatException(p, "Invalid Key", p.getValueAsString(), ECKey.class); } default: return (ECKey) ctxt.handleUnexpectedToken(ECKey.class, p); } }
Example 9
Source File: MailAddressDeserializer.java From james-project with Apache License 2.0 | 5 votes |
@Override public MailAddress deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { String value = jsonParser.getValueAsString(); try { return new MailAddress(value); } catch (AddressException exception) { throw new JsonParseException( jsonParser, String.format("Something went wrong when trying to parse %s into a mail address", value), exception); } }
Example 10
Source File: CountryBindMap.java From kripton with Apache License 2.0 | 4 votes |
/** * parse with jackson */ @Override public Country parseOnJacksonAsString(JsonParser jacksonParser) throws Exception { Country instance = new Country(); String fieldName; if (jacksonParser.getCurrentToken() == null) { jacksonParser.nextToken(); } if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) { jacksonParser.skipChildren(); return instance; } while (jacksonParser.nextToken() != JsonToken.END_OBJECT) { fieldName = jacksonParser.getCurrentName(); jacksonParser.nextToken(); // Parse fields: switch (fieldName) { case "area": // field area (mapped with "area") instance.area=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "callingCode": // field callingCode (mapped with "callingCode") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.callingCode=jacksonParser.getText(); } break; case "code": // field code (mapped with "code") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.code=jacksonParser.getText(); } break; case "id": // field id (mapped with "id") instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "name": // field name (mapped with "name") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.name=jacksonParser.getText(); } break; case "region": // field region (mapped with "region") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.region=jacksonParser.getText(); } break; case "translatedName": // field translatedName (mapped with "translatedName") if (jacksonParser.currentToken()==JsonToken.START_ARRAY) { HashMap<Translation, String> collection=new HashMap<>(); Translation key=null; String value=null; JsonToken current; String tempValue=null; while (jacksonParser.nextToken() != JsonToken.END_ARRAY) { current=jacksonParser.currentToken(); for (int i=0; i<2 ;i++) { while (current != JsonToken.FIELD_NAME) { current=jacksonParser.nextToken(); } jacksonParser.nextValue(); switch(jacksonParser.getCurrentName()) { case "key": { String tempEnum=jacksonParser.getText(); key=StringUtils.hasText(tempEnum)?Translation.valueOf(tempEnum):null; } break; case "value": tempValue=jacksonParser.getValueAsString(); if (jacksonParser.currentToken()==JsonToken.VALUE_STRING && "null".equals(tempValue)) { value=null; } else { if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { value=jacksonParser.getText(); } } break; } } collection.put(key, value); key=null; value=null; jacksonParser.nextToken(); } instance.translatedName=collection; } break; default: jacksonParser.skipChildren(); break;} } return instance; }
Example 11
Source File: Bean81UBindMap.java From kripton with Apache License 2.0 | 4 votes |
/** * parse with jackson */ @Override public Bean81U parseOnJacksonAsString(JsonParser jacksonParser) throws Exception { Bean81U instance = new Bean81U(); String fieldName; if (jacksonParser.getCurrentToken() == null) { jacksonParser.nextToken(); } if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) { jacksonParser.skipChildren(); return instance; } while (jacksonParser.nextToken() != JsonToken.END_OBJECT) { fieldName = jacksonParser.getCurrentName(); jacksonParser.nextToken(); // Parse fields: switch (fieldName) { case "valueInteger": // field valueInteger (mapped with "valueInteger") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.valueInteger=PrimitiveUtils.readInteger(jacksonParser.getText(), null); } break; case "id": // field id (mapped with "id") instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "valueMapStringInteger": // field valueMapStringInteger (mapped with "valueMapStringInteger") if (jacksonParser.currentToken()==JsonToken.START_ARRAY) { HashMap<String, Integer> collection=new HashMap<>(); String key=null; Integer value=null; JsonToken current; String tempValue=null; while (jacksonParser.nextToken() != JsonToken.END_ARRAY) { current=jacksonParser.currentToken(); for (int i=0; i<2 ;i++) { while (current != JsonToken.FIELD_NAME) { current=jacksonParser.nextToken(); } jacksonParser.nextValue(); switch(jacksonParser.getCurrentName()) { case "key": if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { key=jacksonParser.getText(); } break; case "value": tempValue=jacksonParser.getValueAsString(); if (jacksonParser.currentToken()==JsonToken.VALUE_STRING && "null".equals(tempValue)) { value=null; } else { if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { value=PrimitiveUtils.readInteger(jacksonParser.getText(), null); } } break; } } collection.put(key, value); key=null; value=null; jacksonParser.nextToken(); } instance.valueMapStringInteger=collection; } break; case "valueByteArray": // field valueByteArray (mapped with "valueByteArray") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.valueByteArray=Base64Utils.decode(jacksonParser.getValueAsString()); } break; default: jacksonParser.skipChildren(); break;} } return instance; }
Example 12
Source File: CountryBindMap.java From kripton with Apache License 2.0 | 4 votes |
/** * parse with jackson */ @Override public Country parseOnJacksonAsString(JsonParser jacksonParser) throws Exception { Country instance = new Country(); String fieldName; if (jacksonParser.getCurrentToken() == null) { jacksonParser.nextToken(); } if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) { jacksonParser.skipChildren(); return instance; } while (jacksonParser.nextToken() != JsonToken.END_OBJECT) { fieldName = jacksonParser.getCurrentName(); jacksonParser.nextToken(); // Parse fields: switch (fieldName) { case "area": // field area (mapped with "area") instance.area=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "callingCode": // field callingCode (mapped with "callingCode") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.callingCode=jacksonParser.getText(); } break; case "code": // field code (mapped with "code") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.code=jacksonParser.getText(); } break; case "id": // field id (mapped with "id") instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "name": // field name (mapped with "name") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.name=jacksonParser.getText(); } break; case "region": // field region (mapped with "region") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.region=jacksonParser.getText(); } break; case "translatedName": // field translatedName (mapped with "translatedName") if (jacksonParser.currentToken()==JsonToken.START_ARRAY) { HashMap<Translation, String> collection=new HashMap<>(); Translation key=null; String value=null; JsonToken current; String tempValue=null; while (jacksonParser.nextToken() != JsonToken.END_ARRAY) { current=jacksonParser.currentToken(); for (int i=0; i<2 ;i++) { while (current != JsonToken.FIELD_NAME) { current=jacksonParser.nextToken(); } jacksonParser.nextValue(); switch(jacksonParser.getCurrentName()) { case "key": { String tempEnum=jacksonParser.getText(); key=StringUtils.hasText(tempEnum)?Translation.valueOf(tempEnum):null; } break; case "value": tempValue=jacksonParser.getValueAsString(); if (jacksonParser.currentToken()==JsonToken.VALUE_STRING && "null".equals(tempValue)) { value=null; } else { if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { value=jacksonParser.getText(); } } break; } } collection.put(key, value); key=null; value=null; jacksonParser.nextToken(); } instance.translatedName=collection; } break; default: jacksonParser.skipChildren(); break;} } return instance; }
Example 13
Source File: FieldTypeDeserializer.java From cloudstreetmarket.com with GNU General Public License v3.0 | 4 votes |
@Override public FieldType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String fieldTypeString = jp.getValueAsString(); return FieldType.valueOf(fieldTypeString.toUpperCase()); }
Example 14
Source File: Bean81TBindMap.java From kripton with Apache License 2.0 | 4 votes |
/** * parse with jackson */ @Override public Bean81T parseOnJacksonAsString(JsonParser jacksonParser) throws Exception { Bean81T instance = new Bean81T(); String fieldName; if (jacksonParser.getCurrentToken() == null) { jacksonParser.nextToken(); } if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) { jacksonParser.skipChildren(); return instance; } while (jacksonParser.nextToken() != JsonToken.END_OBJECT) { fieldName = jacksonParser.getCurrentName(); jacksonParser.nextToken(); // Parse fields: switch (fieldName) { case "valueInteger": // field valueInteger (mapped with "valueInteger") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.valueInteger=PrimitiveUtils.readInteger(jacksonParser.getText(), null); } break; case "id": // field id (mapped with "id") instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "valueMapStringInteger": // field valueMapStringInteger (mapped with "valueMapStringInteger") if (jacksonParser.currentToken()==JsonToken.START_ARRAY) { HashMap<String, Integer> collection=new HashMap<>(); String key=null; Integer value=null; JsonToken current; String tempValue=null; while (jacksonParser.nextToken() != JsonToken.END_ARRAY) { current=jacksonParser.currentToken(); for (int i=0; i<2 ;i++) { while (current != JsonToken.FIELD_NAME) { current=jacksonParser.nextToken(); } jacksonParser.nextValue(); switch(jacksonParser.getCurrentName()) { case "key": if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { key=jacksonParser.getText(); } break; case "value": tempValue=jacksonParser.getValueAsString(); if (jacksonParser.currentToken()==JsonToken.VALUE_STRING && "null".equals(tempValue)) { value=null; } else { if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { value=PrimitiveUtils.readInteger(jacksonParser.getText(), null); } } break; } } collection.put(key, value); key=null; value=null; jacksonParser.nextToken(); } instance.valueMapStringInteger=collection; } break; case "valueByteArray": // field valueByteArray (mapped with "valueByteArray") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.valueByteArray=Base64Utils.decode(jacksonParser.getValueAsString()); } break; default: jacksonParser.skipChildren(); break;} } return instance; }
Example 15
Source File: EmoCoordinate.java From emodb with Apache License 2.0 | 4 votes |
@Override protected Text narrow(JsonParser parser) throws IOException { if (parser.getCurrentToken() != JsonToken.START_OBJECT) { return null; } String id = null; String table = null; JsonToken currentToken = parser.nextToken(); while ((id == null || table == null) && currentToken != JsonToken.END_OBJECT) { if (currentToken != JsonToken.FIELD_NAME) { // This should always be a field. Something is amiss. throw new IOException("Field not found at expected location"); } String fieldName = parser.getText(); currentToken = parser.nextToken(); if (id == null && fieldName.equals(Intrinsic.ID)) { if (currentToken != JsonToken.VALUE_STRING) { return null; } id = parser.getValueAsString(); currentToken = parser.nextToken(); } else if (table == null && fieldName.equals(Intrinsic.TABLE)) { if (currentToken != JsonToken.VALUE_STRING) { return null; } table = parser.getValueAsString(); currentToken = parser.nextToken(); } else { currentToken = skipValue(parser); } } if (id == null || table == null) { return null; } return new Text(Coordinate.of(table, id).toString()); }
Example 16
Source File: IsParser.java From robe with GNU Lesser General Public License v3.0 | 4 votes |
default boolean isValid(JsonParser o) throws IOException { return o.getValueAsString() != null && !o.getValueAsString().trim().isEmpty(); }
Example 17
Source File: DatabaseEntities.java From cassandra-backup with Apache License 2.0 | 4 votes |
@Override public DatabaseEntities deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { final String valueAsString = p.getValueAsString(); return valueAsString == null ? DatabaseEntities.empty() : DatabaseEntities.parse(valueAsString); }
Example 18
Source File: SecretIdentifierDeserializer.java From strongbox with Apache License 2.0 | 4 votes |
@Override public SecretIdentifier deserialize(JsonParser parser, DeserializationContext context) throws IOException { return new SecretIdentifier(parser.getValueAsString()); }
Example 19
Source File: LibraryUpdaterTask.java From android-viewer-for-khan-academy with GNU General Public License v3.0 | 4 votes |
private ContentValues parseObject(JsonParser parser, SQLiteDatabase tempDb, String parentId, int seq) throws JsonParseException, IOException { // TODO : Grab id of root topic here, and store it in shared prefs, in case it ever // changes. Currently we assume "root" and a change would be catastrophic. ContentValues result = new ContentValues(); ChildArrayResults childResults = null; boolean badKind = false; result.put("parentTopic_id", parentId); result.put("seq", seq); while (parser.nextValue() != JsonToken.END_OBJECT) { // Allows us to burn through the rest of the object once we discover it's an exercise or something else we don't care about. if (badKind) continue; String fieldName = parser.getCurrentName(); // Keys present will determine object type. if (stringFields.contains(fieldName)) { // Use getValueAsString over getText; getText returns "null" while getValueAsString returns null. String value = parser.getValueAsString(); result.put(fieldName, value); if ("id".equals(fieldName)) { if (childResults != null) { addParentIdToChildren(tempDb, childResults, value); } } } else if (intFields.contains(fieldName)) { result.put(fieldName, parser.getIntValue()); } else if (booleanFields.contains(fieldName)) { result.put(fieldName, parser.getBooleanValue()); } else if ("children".equals(fieldName)) { childResults = parseChildArray(parser, tempDb, result.containsKey("id") ? result.getAsString("id") : null); result.put("video_count", childResults.videoCount); result.put("child_kind", childResults.childKind); result.put("thumb_id", childResults.thumbId); } else if ("download_urls".equals(fieldName)) { parseDownloadUrls(parser, result); } else if (null == fieldName) { // Noop. Just in case. } else { JsonToken next = parser.getCurrentToken(); if (next == JsonToken.START_OBJECT || next == JsonToken.START_ARRAY) { // Skip this object or array, leaving us pointing at the matching end_object / end_array token. parser.skipChildren(); } } } // Ignore types we don't need. if (badKind) { return null; } // Having parsed this whole object, we can insert it. if (result.containsKey("kind")) { String kind = result.getAsString("kind"); if ("Topic".equals(kind)) { if (result.containsKey("id")) { result.put("_id", result.getAsString("id")); result.remove("id"); } if (result.containsKey("child_kind")) { String child_kind = result.getAsString("child_kind"); if ("Topic".equals(child_kind) || "Video".equals(child_kind)) { insertTopic(tempDb, result); } } } else if ("Video".equals(kind)) { if (result.containsKey("id")) { result.put("video_id", result.getAsString("id")); result.remove("id"); } insertTopicVideo(tempDb, result); insertVideo(tempDb, result); } } return result; }
Example 20
Source File: RestExecutor.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Override public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { JsonToken startTok = p.getCurrentToken(); if (startTok.isStructStart()) { StringWriter wrt = new StringWriter(4096); JsonGenerator gen = factory.createGenerator(wrt); JsonToken tok = startTok, endTok = startTok == START_ARRAY ? END_ARRAY : END_OBJECT; int cnt = 1; while (cnt > 0) { writeToken(tok, p, gen); tok = p.nextToken(); if (tok == startTok) cnt++; else if (tok == endTok) cnt--; } gen.close(); return wrt.toString(); } return p.getValueAsString(); }