List of usage examples for com.google.gson JsonElement getAsInt
public int getAsInt()
From source file:org.sonarsource.dotnet.shared.sarif.SarifParser10.java
License:Open Source License
@CheckForNull private static Location handleLocation(JsonObject locationObj, @Nullable String message) { String uri = locationObj.get("uri").getAsString(); String absolutePath = uriToAbsolutePath(uri); JsonObject region = locationObj.get("region").getAsJsonObject(); int startLine = region.get("startLine").getAsInt(); JsonElement startColumnOrNull = region.get("startColumn"); int startColumn = startColumnOrNull != null ? startColumnOrNull.getAsInt() : 1; int startLineOffset = startColumn - 1; JsonElement lengthOrNull = region.get("length"); if (lengthOrNull != null) { return new Location(absolutePath, message, startLine, startLineOffset, startLine, startLineOffset + lengthOrNull.getAsInt()); }//from w ww. ja v a 2 s . c o m JsonElement endLineOrNull = region.get("endLine"); int endLine = endLineOrNull != null ? endLineOrNull.getAsInt() : startLine; JsonElement endColumnOrNull = region.get("endColumn"); int endColumn; if (endColumnOrNull != null) { endColumn = endColumnOrNull.getAsInt(); } else if (endLineOrNull != null) { endColumn = endLine == startLine ? startColumn : 1; } else { endColumn = startColumn; } int endLineOffset = endColumn - 1; if (startColumn == endColumn && startLine == endLine) { return null; } return new Location(absolutePath, message, startLine, startLineOffset, endLine, endLineOffset); }
From source file:org.sourcepit.consul.forwarder.GsonUtils.java
License:Apache License
public static Integer getAsInteger(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }/*from w w w . j ava2 s.c om*/ return Integer.valueOf(jsonElement.getAsInt()); }
From source file:org.sourcepit.docker.watcher.ConsulForwarder.java
License:Apache License
private Integer getAsInteger(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { return null; }//w w w.j a v a2 s. c om return Integer.valueOf(jsonElement.getAsInt()); }
From source file:org.springframework.ide.vscode.commons.languageserver.util.Settings.java
License:Open Source License
public Integer getInt(String... names) { try {//from ww w . ja va2s .com JsonElement val = getRawProperty(names); if (val != null) { return val.getAsInt(); } } catch (Exception e) { log.error("", e); } return null; }
From source file:org.structr.core.PropertySetGSONAdapter.java
License:Open Source License
private Object getTypedValue(JsonElement valueElement, String type) { Object value = null;// ww w. j av a 2s. c om if ((type == null) || type.equals("null")) { value = valueElement.getAsJsonNull(); } else if (type.equals("String")) { value = valueElement.getAsString(); } else if (type.equals("Number")) { value = valueElement.getAsNumber(); } else if (type.equals("Boolean")) { value = valueElement.getAsBoolean(); } else if (type.equals("JsonArray")) { value = valueElement.getAsJsonArray(); } else if (type.equals("JsonObject")) { value = valueElement.getAsJsonObject(); } else if (type.equals("Integer")) { value = valueElement.getAsInt(); } else if (type.equals("Long")) { value = valueElement.getAsLong(); } else if (type.equals("Double")) { value = valueElement.getAsDouble(); } else if (type.equals("Float")) { value = valueElement.getAsFloat(); } else if (type.equals("Byte")) { value = valueElement.getAsByte(); } else if (type.equals("Short")) { value = valueElement.getAsShort(); } else if (type.equals("Character")) { value = valueElement.getAsCharacter(); } else if (type.equals("BigDecimal")) { value = valueElement.getAsBigDecimal(); } else if (type.equals("BigInteger")) { value = valueElement.getAsBigInteger(); } return value; }
From source file:org.talend.mdm.query.IndexProcessor.java
License:Open Source License
@Override public TypedExpression process(JsonObject element, MetadataRepository repository) { JsonArray index = element.get("index").getAsJsonArray(); //$NON-NLS-1$ TypedExpression expression = null;// w ww. java 2s. c o m int indexValue = -1; for (int j = 0; j < index.size(); j++) { JsonElement jsonElement = index.get(j); if (jsonElement.isJsonObject()) { JsonObject jsonObject = jsonElement.getAsJsonObject(); expression = Deserializer.getTypedExpression(jsonObject).process(jsonObject, repository); } else if (jsonElement.isJsonPrimitive()) { indexValue = jsonElement.getAsInt(); } } if (expression == null) { throw new IllegalArgumentException("Malformed query (expected expression in '" + index + "'"); } if (indexValue < 0) { throw new IllegalArgumentException("Malformed query (expected 'index' in '" + index + "'"); } if (!(expression instanceof Field)) { throw new IllegalArgumentException("Malformed query (expected a field in expression)"); } return index(((Field) expression).getFieldMetadata(), indexValue); }
From source file:org.terasology.persistence.typeHandling.gson.GsonPersistedDataArray.java
License:Apache License
@Override public TIntList getAsIntegerArray() { TIntList result = new TIntArrayList(size()); for (JsonElement element : array) { result.add(element.getAsInt()); }//from ww w.j a v a 2s . c o m return result; }
From source file:org.testeditor.fixture.web.json.BrowserSetupReader.java
License:Open Source License
private BrowserSetting createBrowserSettting(Entry<String, JsonElement> browserSettingEntry) { BrowserSetting browserSetting = null; String key = browserSettingEntry.getKey(); JsonElement value = browserSettingEntry.getValue(); JsonPrimitive browserSettingAsJsonPrimitive = value.getAsJsonPrimitive(); if (browserSettingAsJsonPrimitive.isString()) { browserSetting = new BrowserSetting(key, value.getAsString()); } else if (browserSettingAsJsonPrimitive.isBoolean()) { browserSetting = new BrowserSetting(key, value.getAsBoolean()); } else if (browserSettingAsJsonPrimitive.isNumber()) { browserSetting = new BrowserSetting(key, value.getAsInt()); }/*from w ww . j a v a 2 s. co m*/ return browserSetting; }
From source file:org.tinymediamanager.scraper.fanarttv.FanartTv.java
License:Apache License
protected GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); // class types builder.registerTypeAdapter(Integer.class, new JsonDeserializer<Integer>() { @Override/*w ww. ja va2 s. c o m*/ public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { return Integer.valueOf(json.getAsInt()); } catch (NumberFormatException e) { return 0; } } }); builder.registerTypeAdapter(Date.class, new DateTypeAdapter()); builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); return builder; }
From source file:org.tinymediamanager.scraper.omdb.service.Controller.java
License:Apache License
private GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); // class types builder.registerTypeAdapter(Integer.class, new JsonDeserializer<Integer>() { @Override// w w w . j a v a 2 s . c om public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { return json.getAsInt(); } catch (NumberFormatException e) { return 0; } } }); builder.registerTypeAdapter(Date.class, new DateTypeAdapter()); return builder; }