當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonPrimitive.isNumber方法代碼示例

本文整理匯總了Java中com.google.gson.JsonPrimitive.isNumber方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonPrimitive.isNumber方法的具體用法?Java JsonPrimitive.isNumber怎麽用?Java JsonPrimitive.isNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gson.JsonPrimitive的用法示例。


在下文中一共展示了JsonPrimitive.isNumber方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: keyToString

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
private String keyToString(JsonElement keyElement) {
    if (keyElement.isJsonPrimitive()) {
        JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            return String.valueOf(primitive.getAsNumber());
        }
        if (primitive.isBoolean()) {
            return Boolean.toString(primitive.getAsBoolean());
        }
        if (primitive.isString()) {
            return primitive.getAsString();
        }
        throw new AssertionError();
    } else if (keyElement.isJsonNull()) {
        return "null";
    } else {
        throw new AssertionError();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:MapTypeAdapterFactory.java

示例2: convert

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
@Override
public JsonPrimitive convert(JsonPrimitive value) {
  if (value == null) {
    return null;
  }
  if (value.isNumber()) {
    return new JsonPrimitive(String.valueOf(value.getAsInt()));
  }
  try {
    Integer.parseInt(value.getAsString());
    // if it parses correctly, it is validated:
    return value;
  } catch (NumberFormatException ex) {
    throw new ConverterException(value, this);
  }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:17,代碼來源:IntegerToStringConverter.java

示例3: Parameter

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
public Parameter(JsonObject param) {
    try {
        setNameAndType(param.get("name").getAsString(), param.get("type").getAsString());
        if(param.get("value").isJsonObject()){
            setJsonContent(param.getAsJsonObject("value"));
        } else {
            JsonPrimitive value = param.getAsJsonPrimitive("value");
            if(value.isString()) {
                setStringContent(value.getAsString());
            } else if(value.isNumber()) {
                setDoubleContent(value.getAsDouble());
            } else if(value.isBoolean()) {
                setBooleanContent(value.getAsBoolean());
            }
        }
    } catch (Exception e){
        throw new IllegalArgumentException("invalid parameter structure");
    }
}
 
開發者ID:DesktopRemoteManagement,項目名稱:DRM-Desktop,代碼行數:20,代碼來源:Parameter.java

示例4: decodeFromPrimitive

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
private Variant decodeFromPrimitive ( final JsonElement json )
{
    final JsonPrimitive jsonPrim = (JsonPrimitive)json;
    if ( jsonPrim.isBoolean () )
    {
        return Variant.valueOf ( jsonPrim.getAsBoolean () );
    }
    else if ( jsonPrim.isNumber () )
    {
        return Variant.valueOf ( jsonPrim.getAsNumber () );
    }
    else
    {
        return VariantEditor.toVariant ( jsonPrim.getAsString () );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:17,代碼來源:VariantJsonDeserializer.java

示例5: findType

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
private String findType(JsonElement value) throws ValidationException
{
	if (!value.isJsonPrimitive()){
		throw new ValidationException("value is an invalid type");
	}

	JsonPrimitive primitiveValue = (JsonPrimitive) value;
	if (primitiveValue.isNumber() || (primitiveValue.isString() && Util.isNumber(value.getAsString())))
	{
		String v = value.getAsString();

		if (!v.contains("."))
		{
			return "long";
		}
		else
		{
			return "double";
		}
	}
	else
		return "string";
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:24,代碼來源:DataPointsParser.java

示例6: keyToString

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
private String keyToString(JsonElement keyElement) {
  if (keyElement.isJsonPrimitive()) {
    JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
    if (primitive.isNumber()) {
      return String.valueOf(primitive.getAsNumber());
    } else if (primitive.isBoolean()) {
      return Boolean.toString(primitive.getAsBoolean());
    } else if (primitive.isString()) {
      return primitive.getAsString();
    } else {
      throw new AssertionError();
    }
  } else if (keyElement.isJsonNull()) {
    return "null";
  } else {
    throw new AssertionError();
  }
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:19,代碼來源:MapTypeAdapterFactory.java

示例7: deserialize

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
@Override
public Holder deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
  JsonObject root = (JsonObject) json;

  ImmutableHolder.Builder builder = ImmutableHolder.builder();

  if (root.has("id")) {
    builder.id(root.get("id").getAsString());
  }

  JsonElement value = root.get(VALUE_PROPERTY);
  if (value == null) {
    throw new JsonParseException(String.format("%s not found for %s in JSON", VALUE_PROPERTY, type));
  }

  if (value.isJsonObject()) {
    final String valueTypeName = value.getAsJsonObject().get(Holder.TYPE_PROPERTY).getAsString();
    try {
      Class<?> valueType = Class.forName(valueTypeName);
      builder.value(context.deserialize(value, valueType));
    } catch (ClassNotFoundException e) {
      throw new JsonParseException(String.format("Couldn't construct value class %s for %s", valueTypeName, type), e);
    }
  } else if (value.isJsonPrimitive()) {
    final JsonPrimitive primitive = value.getAsJsonPrimitive();
    if (primitive.isString()) {
      builder.value(primitive.getAsString());
    } else if (primitive.isNumber()) {
      builder.value(primitive.getAsInt());
    } else if (primitive.isBoolean()) {
      builder.value(primitive.getAsBoolean());
    }
  } else {
    throw new JsonParseException(
        String.format("Couldn't deserialize %s : %s. Not a primitive or object", VALUE_PROPERTY, value));
  }

  return builder.build();

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:41,代碼來源:HolderJsonSerializer.java

示例8: unwarpPrimitive

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
@Override
public Object unwarpPrimitive(JsonPrimitive primitive) {
    if (primitive.isBoolean()) {
        return primitive.getAsBoolean();
    } else if (primitive.isNumber()) {
        return primitive.getAsNumber();
    } else if (primitive.isString()) {
        return primitive.getAsString();
    } else {
        throw new IllegalArgumentException("Unknown primitive type: " + primitive);
    }
}
 
開發者ID:lucko,項目名稱:helper,代碼行數:13,代碼來源:AbstractGsonConverter.java

示例9: deserialize

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
@Override
public UnnamedField deserialize(JsonElement json,
                                Type typeOfT,
                                JsonDeserializationContext context) throws JsonParseException {
    if (!json.isJsonPrimitive()) {
        throw new JsonParseException("Is not a primitive: " + json.toString());
    }

    JsonPrimitive jsonPrimitive = json.getAsJsonPrimitive();

    UnnamedField result = null;

    if (jsonPrimitive.isBoolean()) {
        result = FieldFabric.create(jsonPrimitive.getAsBoolean());
    } else if (jsonPrimitive.isString()) {
        result = FieldFabric.create(jsonPrimitive.getAsString());
    } else if (jsonPrimitive.isNumber()) {
        String numberString = jsonPrimitive.getAsString();
        if (numberString.contains(".")) {
            result = FieldFabric.create(jsonPrimitive.getAsDouble());
        } else {
            result = FieldFabric.create(jsonPrimitive.getAsLong());
        }
    }

    if (result == null) {
        throw new JsonParseException("JsonElement is of unsupported type");
    }

    return result;
}
 
開發者ID:NomenSvyat,項目名稱:SwitchBoxPlugin,代碼行數:32,代碼來源:UnnamedFieldDeserializer.java

示例10: getTypeFor

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
private org.eclipse.leshan.core.model.ResourceModel.Type getTypeFor(JsonPrimitive val) {
    if (val.isBoolean())
        return org.eclipse.leshan.core.model.ResourceModel.Type.BOOLEAN;
    if (val.isString())
        return org.eclipse.leshan.core.model.ResourceModel.Type.STRING;
    if (val.isNumber()) {
        if (val.getAsDouble() == val.getAsLong()) {
            return org.eclipse.leshan.core.model.ResourceModel.Type.INTEGER;
        } else {
            return org.eclipse.leshan.core.model.ResourceModel.Type.FLOAT;
        }
    }
    // use string as default value
    return org.eclipse.leshan.core.model.ResourceModel.Type.STRING;
}
 
開發者ID:IoTKETI,項目名稱:IPE-LWM2M,代碼行數:16,代碼來源:LwM2mNodeDeserializer.java

示例11: write

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
public void write(JsonWriter out, JsonElement value) throws IOException {
    if (value == null || value.isJsonNull()) {
        out.nullValue();
    } else if (value.isJsonPrimitive()) {
        JsonPrimitive primitive = value.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            out.value(primitive.getAsNumber());
        } else if (primitive.isBoolean()) {
            out.value(primitive.getAsBoolean());
        } else {
            out.value(primitive.getAsString());
        }
    } else if (value.isJsonArray()) {
        out.beginArray();
        Iterator it = value.getAsJsonArray().iterator();
        while (it.hasNext()) {
            write(out, (JsonElement) it.next());
        }
        out.endArray();
    } else if (value.isJsonObject()) {
        out.beginObject();
        for (Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
            out.name((String) e.getKey());
            write(out, (JsonElement) e.getValue());
        }
        out.endObject();
    } else {
        throw new IllegalArgumentException("Couldn't write " + value.getClass());
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:31,代碼來源:TypeAdapters.java

示例12: toString

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
/**
 * Gets a human-readable description of the given JsonElement's type.  For example: "a number (4)"
 */
public static String toString(JsonElement json)
{
    String s = org.apache.commons.lang3.StringUtils.abbreviateMiddle(String.valueOf((Object)json), "...", 10);

    if (json == null)
    {
        return "null (missing)";
    }
    else if (json.isJsonNull())
    {
        return "null (json)";
    }
    else if (json.isJsonArray())
    {
        return "an array (" + s + ")";
    }
    else if (json.isJsonObject())
    {
        return "an object (" + s + ")";
    }
    else
    {
        if (json.isJsonPrimitive())
        {
            JsonPrimitive jsonprimitive = json.getAsJsonPrimitive();

            if (jsonprimitive.isNumber())
            {
                return "a number (" + s + ")";
            }

            if (jsonprimitive.isBoolean())
            {
                return "a boolean (" + s + ")";
            }
        }

        return s;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:44,代碼來源:JsonUtils.java

示例13: toString

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
/**
 * Gets a human-readable description of the given JsonElement's type.  For example: "a number (4)"
 */
public static String toString(JsonElement p_151222_0_)
{
    String s = org.apache.commons.lang3.StringUtils.abbreviateMiddle(String.valueOf((Object)p_151222_0_), "...", 10);

    if (p_151222_0_ == null)
    {
        return "null (missing)";
    }
    else if (p_151222_0_.isJsonNull())
    {
        return "null (json)";
    }
    else if (p_151222_0_.isJsonArray())
    {
        return "an array (" + s + ")";
    }
    else if (p_151222_0_.isJsonObject())
    {
        return "an object (" + s + ")";
    }
    else
    {
        if (p_151222_0_.isJsonPrimitive())
        {
            JsonPrimitive jsonprimitive = p_151222_0_.getAsJsonPrimitive();

            if (jsonprimitive.isNumber())
            {
                return "a number (" + s + ")";
            }

            if (jsonprimitive.isBoolean())
            {
                return "a boolean (" + s + ")";
            }
        }

        return s;
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:44,代碼來源:JsonUtils.java

示例14: peek

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
public JsonToken peek() throws IOException {
    if (this.stack.isEmpty()) {
        return JsonToken.END_DOCUMENT;
    }
    Iterator<?> o = peekStack();
    if (o instanceof Iterator) {
        boolean isObject = this.stack.get(this.stack.size() - 2) instanceof JsonObject;
        Iterator<?> iterator = o;
        if (!iterator.hasNext()) {
            return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
        } else {
            if (isObject) {
                return JsonToken.NAME;
            }
            this.stack.add(iterator.next());
            return peek();
        }
    } else if (o instanceof JsonObject) {
        return JsonToken.BEGIN_OBJECT;
    } else {
        if (o instanceof JsonArray) {
            return JsonToken.BEGIN_ARRAY;
        }
        if (o instanceof JsonPrimitive) {
            JsonPrimitive primitive = (JsonPrimitive) o;
            if (primitive.isString()) {
                return JsonToken.STRING;
            }
            if (primitive.isBoolean()) {
                return JsonToken.BOOLEAN;
            }
            if (primitive.isNumber()) {
                return JsonToken.NUMBER;
            }
            throw new AssertionError();
        } else if (o instanceof JsonNull) {
            return JsonToken.NULL;
        } else {
            if (o == SENTINEL_CLOSED) {
                throw new IllegalStateException("JsonReader is closed");
            }
            throw new AssertionError();
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:46,代碼來源:JsonTreeReader.java

示例15: peek

import com.google.gson.JsonPrimitive; //導入方法依賴的package包/類
@Override public JsonToken peek() throws IOException {
  if (stack.isEmpty()) {
    return JsonToken.END_DOCUMENT;
  }

  Object o = peekStack();
  if (o instanceof Iterator) {
    boolean isObject = stack.get(stack.size() - 2) instanceof JsonObject;
    Iterator<?> iterator = (Iterator<?>) o;
    if (iterator.hasNext()) {
      if (isObject) {
        return JsonToken.NAME;
      } else {
        stack.add(iterator.next());
        return peek();
      }
    } else {
      return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
    }
  } else if (o instanceof JsonObject) {
    return JsonToken.BEGIN_OBJECT;
  } else if (o instanceof JsonArray) {
    return JsonToken.BEGIN_ARRAY;
  } else if (o instanceof JsonPrimitive) {
    JsonPrimitive primitive = (JsonPrimitive) o;
    if (primitive.isString()) {
      return JsonToken.STRING;
    } else if (primitive.isBoolean()) {
      return JsonToken.BOOLEAN;
    } else if (primitive.isNumber()) {
      return JsonToken.NUMBER;
    } else {
      throw new AssertionError();
    }
  } else if (o instanceof JsonNull) {
    return JsonToken.NULL;
  } else if (o == SENTINEL_CLOSED) {
    throw new IllegalStateException("JsonReader is closed");
  } else {
    throw new AssertionError();
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:43,代碼來源:JsonTreeReader.java


注:本文中的com.google.gson.JsonPrimitive.isNumber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。