List of usage examples for com.google.gson JsonElement getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive()
From source file:org.apache.tajo.catalog.json.PathDeserializer.java
License:Apache License
@Override public Path deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { return new Path(arg0.getAsJsonPrimitive().getAsString()); }
From source file:org.apache.tajo.json.PathSerializer.java
License:Apache License
@Override public Path deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext context) throws JsonParseException { return new Path(arg0.getAsJsonPrimitive().getAsString()); }
From source file:org.apache.tajo.json.TimeZoneGsonSerdeAdapter.java
License:Apache License
@Override public TimeZone deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext context) throws JsonParseException { return TimeZone.getTimeZone(arg0.getAsJsonPrimitive().getAsString()); }
From source file:org.artemis.toolkit.common.dtSerializer.java
License:Apache License
@Override public newdatatype deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return newdatatype.fromString(json.getAsJsonPrimitive().getAsString()); }
From source file:org.artemis.toolkit.common.orderSerializer.java
License:Apache License
@Override public order deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return order.fromString(json.getAsJsonPrimitive().getAsString()); }
From source file:org.blockartistry.DynSurround.client.footsteps.parsers.AcousticsJsonReader.java
License:MIT License
private IAcoustic solveAcoustic(final JsonElement unsolved) throws JsonParseException { IAcoustic ret = null;//w ww.j a va 2 s. c o m if (unsolved.isJsonObject()) { ret = solveAcousticsCompound(unsolved.getAsJsonObject()); } else if (unsolved.isJsonPrimitive() && unsolved.getAsJsonPrimitive().isString()) { // Is a sound name final BasicAcoustic a = new BasicAcoustic(); prepareDefaults(a); setupSoundName(a, unsolved.getAsString()); ret = a; } if (ret == null) throw new JsonParseException("Unresolved Json element: \r\n" + unsolved.toString()); return ret; }
From source file:org.couchpotato.json.deserializer.JsonBooleanDeserializer.java
License:Open Source License
@Override public JsonBoolean deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { try {//from w ww . ja v a 2 s . c o m String value = arg0.getAsJsonPrimitive().getAsString(); if (value.toLowerCase().equals("true")) { return new JsonBoolean(true); } else if (value.toLowerCase().equals("false")) { return new JsonBoolean(false); } else { return new JsonBoolean(Integer.valueOf(value) != 0); } } catch (ClassCastException e) { throw new JsonParseException("Cannot parse JsonBoolean string '" + arg0.toString() + "'", e); } catch (Exception e) { throw new JsonParseException("Cannot parse JsonBoolean string '" + arg0.toString() + "'", e); } }
From source file:org.cvasilak.jboss.mobile.app.fragments.ServersViewFragment.java
License:Apache License
@Override public void onListItemClick(ListView list, View view, int position, long id) { application.setCurrentActiveServer(serversManager.serverAtIndex(position)); ProgressDialogFragment.showDialog(getActivity(), R.string.queryingServer); application.getOperationsManager().fetchJBossManagementVersion(new Callback() { @Override//from w ww . j a va 2 s. c o m public void onSuccess(JsonElement reply) { ProgressDialogFragment.dismissDialog(getActivity()); // extract the version int version = reply.getAsJsonPrimitive().getAsInt(); // set it for any subsequent calls application.getOperationsManager().setVersion(version); // time to show home page Intent i = new Intent(getActivity(), JBossServerRootActivity.class); startActivity(i); } @Override public void onFailure(Exception e) { ProgressDialogFragment.dismissDialog(getActivity()); ErrorDialogFragment.showDialog(getActivity(), e.getMessage()); } }); }
From source file:org.dashbuilder.dataprovider.backend.elasticsearch.rest.client.impl.jest.ElasticSearchJestClient.java
License:Apache License
/** * Parses a given value (for a given column type) returned by response JSON query body from EL server. * * @param column The data column definition. * @param valueElement The value element from JSON query response to format. * @return The formatted value for the given column type. *//*from w w w .j a va2 s . c om*/ public static Object parseValue(ElasticSearchDataSetDef definition, ElasticSearchDataSetMetadata metadata, DataColumn column, JsonElement valueElement) { if (column == null || valueElement == null || valueElement.isJsonNull()) return null; if (!valueElement.isJsonPrimitive()) throw new RuntimeException("Not expected JsonElement type to parse from query response."); JsonPrimitive valuePrimitive = valueElement.getAsJsonPrimitive(); ColumnType columnType = column.getColumnType(); if (ColumnType.NUMBER.equals(columnType)) { return valueElement.getAsDouble(); } else if (ColumnType.DATE.equals(columnType)) { // We can expect two return core types from EL server when handling dates: // 1.- String type, using the field pattern defined in the index' mappings, when it's result of a query without aggregations. // 2.- Numeric type, when it's result from a scalar function or a value pickup. if (valuePrimitive.isString()) { DateTimeFormatter formatter = null; String datePattern = metadata.getFieldPattern(column.getId()); if (datePattern == null || datePattern.trim().length() == 0) { // If no custom pattern for date field, use the default by EL -> org.joda.time.format.ISODateTimeFormat#dateOptionalTimeParser formatter = ElasticSearchDataSetProvider.EL_DEFAULT_DATETIME_FORMATTER; } else { // Obtain the date value by parsing using the EL pattern specified for this field. formatter = DateTimeFormat.forPattern(datePattern); } DateTime dateTime = formatter.parseDateTime(valuePrimitive.getAsString()); return dateTime.toDate(); } if (valuePrimitive.isNumber()) { return new Date(valuePrimitive.getAsLong()); } throw new UnsupportedOperationException( "Value core type not supported. Expecting string or number when using date core field types."); } // LABEL, TEXT or grouped DATE column types. String valueAsString = valueElement.getAsString(); ColumnGroup columnGroup = column.getColumnGroup(); // For FIXED date values, remove the unnecessary "0" at first character. (eg: replace month "01" to "1") if (columnGroup != null && GroupStrategy.FIXED.equals(columnGroup.getStrategy()) && valueAsString.startsWith("0")) return valueAsString.substring(1); return valueAsString; }
From source file:org.dashbuilder.dataprovider.backend.elasticsearch.rest.impl.jest.ElasticSearchJestClient.java
License:Apache License
/** * Parses a given value (for a given column type) returned by response JSON query body from EL server. * * @param column The data column definition. * @param valueElement The value element from JSON query response to format. * @return The object value for the given column type. *//* w w w .jav a2s. c o m*/ public Object parseValue(DataSetMetadata metadata, DataColumn column, JsonElement valueElement) throws ParseException { if (column == null || valueElement == null || valueElement.isJsonNull()) return null; if (!valueElement.isJsonPrimitive()) throw new RuntimeException("Not expected JsonElement type to parse from query response."); ElasticSearchDataSetDef def = (ElasticSearchDataSetDef) metadata.getDefinition(); JsonPrimitive valuePrimitive = valueElement.getAsJsonPrimitive(); ColumnType columnType = column.getColumnType(); if (ColumnType.TEXT.equals(columnType)) { return typeMapper.parseText(def, column.getId(), valueElement.getAsString()); } else if (ColumnType.LABEL.equals(columnType)) { boolean isColumnGroup = column.getColumnGroup() != null && column.getColumnGroup().getStrategy().equals(GroupStrategy.FIXED); return typeMapper.parseLabel(def, column.getId(), valueElement.getAsString(), isColumnGroup); } else if (ColumnType.NUMBER.equals(columnType)) { return typeMapper.parseNumeric(def, column.getId(), valueElement.getAsString()); } else if (ColumnType.DATE.equals(columnType)) { // We can expect two return core types from EL server when handling dates: // 1.- String type, using the field pattern defined in the index' mappings, when it's result of a query without aggregations. // 2.- Numeric type, when it's result from a scalar function or a value pickup. if (valuePrimitive.isString()) { return typeMapper.parseDate(def, column.getId(), valuePrimitive.getAsString()); } if (valuePrimitive.isNumber()) { return typeMapper.parseDate(def, column.getId(), valuePrimitive.getAsLong()); } } throw new UnsupportedOperationException("Cannot parse value for column with id [" + column.getId() + "] (Data Set UUID [" + def.getUUID() + "]). Value core type not supported. Expecting string or number or date core field types."); }