List of usage examples for com.fasterxml.jackson.core JsonParser getValueAsString
public String getValueAsString() throws IOException, JsonParseException
From source file:com.microsoft.azure.storage.table.TableStorageErrorDeserializer.java
/** * Parses the error exception details from the Json-formatted response. * /*ww w. j av a2s . c o m*/ * @param parser * the {@link JsonParser} to use for parsing * @throws IOException * if an error occurs while accessing the stream with Json. * @throws JsonParseException * if an error occurs while parsing the stream. */ private static HashMap<String, String[]> parseJsonErrorException(JsonParser parser) throws JsonParseException, IOException { HashMap<String, String[]> additionalDetails = new HashMap<String, String[]>(); parser.nextToken(); JsonUtilities.assertIsStartObjectJsonToken(parser); parser.nextToken(); JsonUtilities.assertIsFieldNameJsonToken(parser); while (parser.getCurrentToken() != JsonToken.END_OBJECT) { if (parser.getCurrentName().equals(TableConstants.ErrorConstants.ERROR_MESSAGE)) { parser.nextToken(); additionalDetails.put(TableConstants.ErrorConstants.ERROR_MESSAGE, new String[] { parser.getValueAsString() }); } else if (parser.getCurrentName().equals(TableConstants.ErrorConstants.ERROR_EXCEPTION_TYPE)) { parser.nextToken(); additionalDetails.put(TableConstants.ErrorConstants.ERROR_EXCEPTION_TYPE, new String[] { parser.getValueAsString() }); } else if (parser.getCurrentName().equals(TableConstants.ErrorConstants.ERROR_EXCEPTION_STACK_TRACE)) { parser.nextToken(); additionalDetails.put(Constants.ERROR_EXCEPTION_STACK_TRACE, new String[] { parser.getValueAsString() }); } parser.nextToken(); } return additionalDetails; }
From source file:org.elasticsearch.client.sniff.ElasticsearchHostsSniffer.java
private static HttpHost readHost(String nodeId, JsonParser parser, Scheme scheme) throws IOException { HttpHost httpHost = null;/* w ww. j a v a2 s . c o m*/ 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.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; }/* ww w.j a v a2 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.microsoft.azure.storage.table.TableStorageErrorDeserializer.java
/** * Gets the Extended Error information./*www. j a va 2s. c om*/ * * @return the Extended Error information. * * @param reader * the input stream to read error details from. * @param format * The {@link TablePayloadFormat} to use for parsing * @throws IOException * if an error occurs while accessing the stream with Json. * @throws JsonParseException * if an error occurs while parsing the stream. */ public static StorageExtendedErrorInformation getExtendedErrorInformation(final Reader reader, final TablePayloadFormat format) throws JsonParseException, IOException { JsonFactory jsonFactory = new JsonFactory(); JsonParser parser = jsonFactory.createParser(reader); try { final StorageExtendedErrorInformation errorInfo = new StorageExtendedErrorInformation(); if (!parser.hasCurrentToken()) { parser.nextToken(); } JsonUtilities.assertIsStartObjectJsonToken(parser); parser.nextToken(); JsonUtilities.assertIsFieldNameJsonToken(parser); JsonUtilities.assertIsExpectedFieldName(parser, "odata.error"); // start getting extended error information parser.nextToken(); JsonUtilities.assertIsStartObjectJsonToken(parser); // get code parser.nextValue(); JsonUtilities.assertIsExpectedFieldName(parser, TableConstants.ErrorConstants.ERROR_CODE); errorInfo.setErrorCode(parser.getValueAsString()); // get message parser.nextToken(); JsonUtilities.assertIsFieldNameJsonToken(parser); JsonUtilities.assertIsExpectedFieldName(parser, TableConstants.ErrorConstants.ERROR_MESSAGE); parser.nextToken(); JsonUtilities.assertIsStartObjectJsonToken(parser); parser.nextValue(); JsonUtilities.assertIsExpectedFieldName(parser, "lang"); parser.nextValue(); JsonUtilities.assertIsExpectedFieldName(parser, "value"); errorInfo.setErrorMessage(parser.getValueAsString()); parser.nextToken(); JsonUtilities.assertIsEndObjectJsonToken(parser); parser.nextToken(); // get innererror if it exists if (parser.getCurrentToken() == JsonToken.FIELD_NAME) { JsonUtilities.assertIsExpectedFieldName(parser, TableConstants.ErrorConstants.INNER_ERROR); errorInfo.getAdditionalDetails().putAll(parseJsonErrorException(parser)); parser.nextToken(); } // end code object JsonUtilities.assertIsEndObjectJsonToken(parser); // end odata.error object parser.nextToken(); JsonUtilities.assertIsEndObjectJsonToken(parser); return errorInfo; } finally { parser.close(); } }
From source file:demo.domain.GrantedAuthorityDeserializer.java
@Override public SimpleGrantedAuthority deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { return new SimpleGrantedAuthority(jp.getValueAsString()); }
From source file:org.zalando.jackson.datatype.money.CurrencyDeserializer.java
@Override public Currency deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { final String currencyCode = parser.getValueAsString(); return Currency.getInstance(currencyCode); }
From source file:com.axibase.tsd.util.SeverityDeserializer.java
@Override public Severity deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { return codeToSeverity.get(parser.getValueAsString()); }
From source file:com.tigerpenguin.places.deserializer.HtmlStringDeserializer.java
@Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { String value = jsonParser.getValueAsString(); value = Html.fromHtml(value).toString(); return value; }
From source file:com.codepine.api.testrail.internal.CsvToListDeserializer.java
@Override public List<String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (jp.getValueAsString() == null) { return null; }//from w w w . ja v a 2s.c o m return Splitter.on(',').trimResults().omitEmptyStrings().splitToList(jp.getValueAsString()); }
From source file:com.helpmobile.rest.mapper.TrimModule.java
public TrimModule() { addDeserializer(String.class, new StdScalarDeserializer<String>(String.class) { @Override//w w w . ja v a 2 s . c o m public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { return jp.getValueAsString().trim(); } }); }