本文整理了Java中com.google.gson.JsonElement.getAsShort()
方法的一些代码示例,展示了JsonElement.getAsShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsShort()
方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsShort
[英]convenience method to get this element as a primitive short value.
[中]将此元素作为基元短值获取的简便方法。
代码示例来源:origin: searchbox-io/Jest
Object o = id.getAsShort();
return (T) o;
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: fenix-framework/fenix-framework
public static Short getShortFromJson(JsonElement value) {
if (value.isJsonNull()) {
return null;
}
return value.getAsShort();
}
代码示例来源:origin: Dytanic/CloudNet
public short getShort(String key)
{
if (!dataCatcher.has(key)) return 0;
return dataCatcher.get(key).getAsShort();
}
代码示例来源:origin: Nextdoor/bender
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: fesch/CanZE
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: Odoo-mobile/framework
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.gson
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: com.google/gson
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: eatnumber1/google-gson
/**
* convenience method to get this array as a primitive short if it contains a single element.
*
* @return get this element as a primitive short if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid short.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public short getAsShort() {
if (elements.size() == 1) {
return elements.get(0).getAsShort();
}
throw new IllegalStateException();
}
代码示例来源:origin: com.capitalone.dashboard/core
private static ObjectId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
if (json instanceof JsonObject) {
JsonObject jo = (JsonObject) json;
return new ObjectId(jo.get("timestamp").getAsInt(), jo.get("machineIdentifier").getAsInt(), jo.get("processIdentifier").getAsShort(), jo.get("counter").getAsInt());
}
return new ObjectId(json.getAsString());
}
代码示例来源:origin: asakusafw/asakusafw
@Override
public void shortProperty(PropertyName name, JsonObject context) throws IOException {
JsonElement prop = property(context, name);
if (prop == null) {
return;
}
builder.add(name, prop.getAsShort());
}
代码示例来源:origin: eatnumber1/google-gson
public Short deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
try {
return json.getAsShort();
} catch (NumberFormatException e) {
throw new JsonSyntaxException(e);
} catch (UnsupportedOperationException e) {
throw new JsonSyntaxException(e);
} catch (IllegalStateException e) {
throw new JsonSyntaxException(e);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
return (T) (Byte) input.getAsByte();
} else if (expected == short.class || expected == Short.class) {
return (T) (Short) input.getAsShort();
} else if (expected == int.class || expected == Integer.class) {
return (T) (Integer) input.getAsInt();
代码示例来源:origin: io.searchbox/jest-common
Object o = id.getAsShort();
return (T) o;
代码示例来源:origin: io.brooklyn/brooklyn-core
return (T) (Byte) input.getAsByte();
} else if (expected == short.class || expected == Short.class) {
return (T) (Short) input.getAsShort();
} else if (expected == int.class || expected == Integer.class) {
return (T) (Integer) input.getAsInt();
代码示例来源:origin: com.musala.atmosphere/atmosphere-commons
break;
case SHORT:
pack.putShort(key, elementValue.getAsShort());
break;
case BYTE:
代码示例来源:origin: Symantec/hendrix
@Test
public void testRuleSerialization() {
Condition one = new OrCondition(Arrays.asList((Condition) new EqualsCondition("header1", "val1"),
(Condition) new JavaRegexCondition("header", "\\d+")));
Condition two = new EqualsCondition("header2", "val2");
Condition condition = new AndCondition(Arrays.asList(one, two));
Action action = new TemplatedAlertAction((short) 2, (short) 2);
SimpleRule rule = new SimpleRule((short) 123, "hello", true, condition, action);
String jsonRule = RuleSerializer.serializeRuleToJSONString(rule, false);
JsonObject object = new Gson().fromJson(jsonRule, JsonObject.class);
assertEquals(123, object.get("ruleId").getAsShort());
assertEquals("hello", object.get("name").getAsString());
JsonObject actionArray = object.get("actions").getAsJsonArray().get(0).getAsJsonObject();
assertEquals(Utils.CLASSNAME_FORWARD_MAP.get(TemplatedAlertAction.class.getCanonicalName()),
actionArray.get("type").getAsString());
}
代码示例来源:origin: apache/incubator-edgent
@Test
public void testValueOfNumber() {
JsonObject joShort = JsonFunctions.valueOfNumber("propName").apply(Short.MAX_VALUE);
assertEquals(Short.MAX_VALUE, joShort.get("propName").getAsShort());
JsonObject joInt = JsonFunctions.valueOfNumber("propName").apply(Integer.MAX_VALUE);
assertEquals(Integer.MAX_VALUE, joInt.get("propName").getAsInt());
JsonObject joLong = JsonFunctions.valueOfNumber("propName").apply(Long.MAX_VALUE);
assertEquals(Long.MAX_VALUE, joLong.get("propName").getAsLong());
JsonObject joFloat = JsonFunctions.valueOfNumber("propName").apply(Float.MAX_VALUE);
assertEquals(Float.MAX_VALUE, joFloat.get("propName").getAsFloat(), 0.0f);
JsonObject joDouble = JsonFunctions.valueOfNumber("propName").apply(Double.MAX_VALUE);
assertEquals(Double.MAX_VALUE, joDouble.get("propName").getAsDouble(), 0.0d);
}
内容来源于网络,如有侵权,请联系作者删除!