本文整理汇总了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;
}