本文整理匯總了Java中org.codehaus.jackson.JsonParser.getLongValue方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.getLongValue方法的具體用法?Java JsonParser.getLongValue怎麽用?Java JsonParser.getLongValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonParser
的用法示例。
在下文中一共展示了JsonParser.getLongValue方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public Instant deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Instant(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser();
final DateTime dateTime = formatter.parseDateTime(str);
return new Instant(dateTime.getMillis());
}
throw ctxt.mappingException(Instant.class);
}
示例2: _parseDate
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
protected java.util.Date _parseDate(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
try
{
if (localJsonToken == JsonToken.VALUE_NUMBER_INT)
return new java.util.Date(paramJsonParser.getLongValue());
if (localJsonToken == JsonToken.VALUE_STRING)
{
String str = paramJsonParser.getText().trim();
if (str.length() == 0)
return null;
return paramDeserializationContext.parseDate(str);
}
throw paramDeserializationContext.mappingException(this._valueClass);
}
catch (IllegalArgumentException localIllegalArgumentException)
{
}
throw paramDeserializationContext.weirdStringException(this._valueClass, "not a valid representation (error: " + localIllegalArgumentException.getMessage() + ")");
}
示例3: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public Duration deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws JsonParseException, IOException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Duration(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
return formatter.parsePeriod(str).toStandardDuration();
}
throw ctxt.mappingException(Duration.class);
}
示例4: _parseLongPrimitive
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
protected final long _parseLongPrimitive(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
long l1 = 0L;
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
if ((localJsonToken == JsonToken.VALUE_NUMBER_INT) || (localJsonToken == JsonToken.VALUE_NUMBER_FLOAT))
l1 = paramJsonParser.getLongValue();
do
while (true)
{
return l1;
if (localJsonToken != JsonToken.VALUE_STRING)
break;
String str = paramJsonParser.getText().trim();
if (str.length() == 0)
continue;
try
{
long l2 = NumberInput.parseLong(str);
return l2;
}
catch (IllegalArgumentException localIllegalArgumentException)
{
throw paramDeserializationContext.weirdStringException(this._valueClass, "not a valid long value");
}
}
while (localJsonToken == JsonToken.VALUE_NULL);
throw paramDeserializationContext.mappingException(this._valueClass);
}
示例5: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
public T deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException
{
JsonToken localJsonToken = paramJsonParser.getCurrentToken();
if (localJsonToken == JsonToken.VALUE_NUMBER_INT)
return new DateTime(paramJsonParser.getLongValue(), DateTimeZone.UTC);
if (localJsonToken == JsonToken.VALUE_STRING)
{
String str = paramJsonParser.getText().trim();
if (str.length() == 0)
return null;
return new DateTime(str, DateTimeZone.UTC);
}
throw paramDeserializationContext.mappingException(getValueClass());
}
示例6: parseBackendResponse
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
private static BackendResponse parseBackendResponse(JsonParser parser) throws IOException {
try {
// Sanity check: verify that we got "Json Object":
if (parser.nextToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected data to start with an Object");
}
long responseKey = 0;
int delay = 0;
int numItems = 0;
int itemSize = 0;
String[] items = null;
JsonToken current;
while (parser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = parser.getCurrentName();
// advance
current = parser.nextToken();
if (fieldName.equals("responseKey")) {
responseKey = parser.getLongValue();
} else if (fieldName.equals("delay")) {
delay = parser.getIntValue();
} else if (fieldName.equals("itemSize")) {
itemSize = parser.getIntValue();
} else if (fieldName.equals("numItems")) {
numItems = parser.getIntValue();
} else if (fieldName.equals("items")) {
// expect numItems to be populated before hitting this
if (numItems == 0) {
throw new IllegalStateException("Expected numItems > 0");
}
items = new String[numItems];
if (current == JsonToken.START_ARRAY) {
int j = 0;
// For each of the records in the array
while (parser.nextToken() != JsonToken.END_ARRAY) {
items[j++] = parser.getText();
}
} else {
// System.out.println("Error: items should be an array: skipping.");
parser.skipChildren();
}
}
}
return new BackendResponse(responseKey, delay, numItems, itemSize, items);
} finally {
parser.close();
}
}
示例7: deserialize
import org.codehaus.jackson.JsonParser; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
JsonProcessingException {
String tokenValue = null;
String tokenType = null;
String refreshToken = null;
Long expiresIn = null;
Set<String> scope = null;
Map<String, Object> additionalInformation = new LinkedHashMap<String, Object>();
// TODO What should occur if a parameter exists twice
while (jp.nextToken() != JsonToken.END_OBJECT) {
String name = jp.getCurrentName();
jp.nextToken();
if (OAuth2AccessToken.ACCESS_TOKEN.equals(name)) {
tokenValue = jp.getText();
}
else if (OAuth2AccessToken.TOKEN_TYPE.equals(name)) {
tokenType = jp.getText();
}
else if (OAuth2AccessToken.REFRESH_TOKEN.equals(name)) {
refreshToken = jp.getText();
}
else if (OAuth2AccessToken.EXPIRES_IN.equals(name)) {
try {
expiresIn = jp.getLongValue();
} catch (JsonParseException e) {
expiresIn = Long.valueOf(jp.getText());
}
}
else if (OAuth2AccessToken.SCOPE.equals(name)) {
String text = jp.getText();
scope = OAuth2Utils.parseParameterList(text);
} else {
additionalInformation.put(name, jp.readValueAs(Object.class));
}
}
// TODO What should occur if a required parameter (tokenValue or tokenType) is missing?
DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(tokenValue);
accessToken.setTokenType(tokenType);
if (expiresIn != null) {
accessToken.setExpiration(new Date(System.currentTimeMillis() + (expiresIn * 1000)));
}
if (refreshToken != null) {
accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
}
accessToken.setScope(scope);
accessToken.setAdditionalInformation(additionalInformation);
return accessToken;
}