Java Code Examples for com.google.gson.JsonElement#getAsFloat()
The following examples show how to use
com.google.gson.JsonElement#getAsFloat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Configuration.java From supbot with MIT License | 6 votes |
/** * Generalized private method to get value from the saved name value pair configuration * @param name name * @param _defautlt default value * @return returns value from the configuration, returns _default if not found */ private Object GetConfig(String name, Object _defautlt){ try { JsonObject jsonObject = ReadJsonObject(); JsonElement result = jsonObject.get(name); if(_defautlt.getClass() == String.class) return result.getAsString(); if(_defautlt.getClass() == Integer.class) return result.getAsInt(); if(_defautlt.getClass() == Float.class) return result.getAsFloat(); if(_defautlt.getClass() == Boolean.class) return result.getAsBoolean(); } catch (IOException | NullPointerException e) { Log.p(e); //Log.e("Could not find config file or config, returning default"); } return _defautlt; }
Example 2
Source File: SqlBuilderSerializer.java From das with Apache License 2.0 | 5 votes |
Supplier toPrimitive(JsonObject obj){ if(!obj.has("type")){ return ()-> new Object(); } String type = obj.get("type").getAsString(); JsonElement primitive = obj.get("value"); if(type.equals(String.class.getSimpleName())){ return () -> primitive.getAsString(); } if(type.equals(Long.class.getSimpleName())){ return () -> primitive.getAsLong(); } if(type.equals(Integer.class.getSimpleName())){ return () -> primitive.getAsInt(); } if(type.equals(Boolean.class.getSimpleName())){ return () -> primitive.getAsBoolean(); } if(type.equals(Float.class.getSimpleName())){ return () -> primitive.getAsFloat(); } if(type.equals(Date.class.getName())){ return () -> new Date(primitive.getAsLong()); } if(type.equals(Timestamp.class.getName())){ return () -> new Timestamp(primitive.getAsLong()); } return () -> null; }
Example 3
Source File: GsonHelper.java From weixin-java-tools with Apache License 2.0 | 4 votes |
public static Float getAsFloat(JsonElement element) { return isNull(element) ? null : element.getAsFloat(); }
Example 4
Source File: KcaBattle.java From kcanotify_h5-master with GNU General Public License v3.0 | 4 votes |
public static int cnv(JsonElement value) { Float f = value.getAsFloat(); return f.intValue(); }
Example 5
Source File: MsgDefTypeAdapter.java From Android with MIT License | 4 votes |
public float parseFloat(String key) { JsonElement element = object.get(key); if (element == null) return 0; return element.getAsFloat(); }
Example 6
Source File: KcaBattle.java From kcanotify with GNU General Public License v3.0 | 4 votes |
public static int cnv(JsonElement value) { Float f = value.getAsFloat(); return f.intValue(); }
Example 7
Source File: JsonElementConversionFactory.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Override FloatValue convertField(JsonElement value) { return new FloatValue(value.getAsFloat()); }
Example 8
Source File: JsonElementConversionFactory.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Override FloatValue convertField(JsonElement value) { return new FloatValue(value.getAsFloat()); }
Example 9
Source File: JsonElementConversionFactory.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Override Object convertField(JsonElement value) { return value.getAsFloat(); }
Example 10
Source File: JsonUtils.java From ProtocolSupport with GNU Affero General Public License v3.0 | 4 votes |
public static float getAsFloat(JsonElement jsonElement, String s) { if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) { return jsonElement.getAsFloat(); } throw new JsonSyntaxException("Expected " + s + " to be a Float, was " + toString(jsonElement)); }
Example 11
Source File: GsonHelper.java From weixin-java-tools with Apache License 2.0 | 4 votes |
public static Float getAsFloat(JsonElement element) { return isNull(element) ? null : element.getAsFloat(); }