private <S> S readValue(JsonObject jsonObject, TypeToken<S> defaultTypeToken) throws IOException { try { TypeToken<S> actualTypeToken; if (jsonObject.isJsonNull()) { return null; } else if (jsonObject.has(OBJECT_TYPE)) { String className = jsonObject.get(OBJECT_TYPE).getAsString(); Class<S> klazz = (Class<S>) Class.forName(className); actualTypeToken = TypeToken.get(klazz); } else if (defaultTypeToken != null) { actualTypeToken = defaultTypeToken; } else { throw new IOException("Could not determine TypeToken."); } TypeAdapter<S> delegate = this.gson.getDelegateAdapter(this.factory, actualTypeToken); S value = delegate.fromJsonTree(jsonObject.get(OBJECT_DATA)); return value; } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } }
private void register( JsonObject json ) { if( json == null || json.isJsonNull() ) { throw new JsonSyntaxException( "Json cannot be null" ); } String type = this.ctx.appendModId( JsonUtils.getString( json, "type" ) ); if( type.isEmpty() ) { throw new JsonSyntaxException( "Recipe type can not be an empty string" ); } IAERecipeFactory factory = this.factories.get( new ResourceLocation( type ) ); if( factory == null ) { throw new JsonSyntaxException( "Unknown recipe type: " + type ); } factory.register( json, this.ctx ); }
private static Map<String, Boolean> getReadOrWriteAccessDetails(String type, Map<String, Boolean> accessMap, String publicIp, String conditionStr, JsonObject conditionJsonObject, List<String> conditionList) { if ((conditionJsonObject.size() == 0) && (conditionList.isEmpty()) && null == conditionStr) { accessMap.put(type, true); } if (!conditionJsonObject.isJsonNull()) { if (conditionJsonObject.toString().equals(publicIp)) { accessMap.put(type, true); } } else if (null != conditionStr && conditionStr.contains(publicIp)) { accessMap.put(type, true); } else if (conditionList.contains(publicIp)) { accessMap.put(type, true); } return accessMap; }
/** * The offset setter. * <p> * <b>Note:</b> If {@link #context_uri(String)} has been set and corresponds to an album or playlist object, an * offset can be specified either by track {@code uri} OR {@code position}. If both are present the request will * return an error. If incorrect values are provided for {@code position} or {@code uri}, the request may be * accepted but with an unpredictable resulting action on playback. * * @param offset Optional. Indicates from where in the context playback should start. Only available when * {@link #context_uri(String)} corresponds to an album or playlist object, or when the * {@link #uris(JsonArray)} parameter is used. <br> The {@code position} parameter in the * {@code offset} object is zero based and can’t be negative. <br> The {@code uri} parameter in the * {@code offset} object is a string representing the URI of the item to start at. * @return A {@link StartResumeUsersPlaybackRequest.Builder}. */ public Builder offset(final JsonObject offset) { assert (offset != null); assert (!offset.isJsonNull()); return setBodyParameter("offset", offset); }
public ExternalId createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } Map<String, String> map = new Gson().fromJson(jsonObject, Map.class); return new ExternalId.Builder() .setExternalIds(map) .build(); } }
public ExternalUrl createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } Map<String, String> map = new Gson().fromJson(jsonObject, Map.class); return new ExternalUrl.Builder() .setExternalUrls(map) .build(); } }
public Restrictions createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new Restrictions.Builder() .setReason( hasAndNotNull(jsonObject, "reason") ? jsonObject.get("reason").getAsString() : null) .build(); } }
public SnapshotResult createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new SnapshotResult.Builder() .setSnapshotId( hasAndNotNull(jsonObject, "snapshot_id") ? jsonObject.get("snapshot_id").getAsString() : null) .build(); } }
public Cursor createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new Cursor.Builder() .setAfter( hasAndNotNull(jsonObject, "after") ? jsonObject.get("after").getAsString() : null) .build(); } }
public PlaylistTrackPosition createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new PlaylistTrackPosition.Builder() .setPositions( hasAndNotNull(jsonObject, "positions") ? new Gson().fromJson( jsonObject.getAsJsonArray("positions"), int[].class) : null) .setUri( hasAndNotNull(jsonObject, "uri") ? jsonObject.get("uri").getAsString() : null) .build(); } }
public PlaylistTracksInformation createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new PlaylistTracksInformation.Builder() .setHref( hasAndNotNull(jsonObject, "href") ? jsonObject.get("href").getAsString() : null) .setTotal( hasAndNotNull(jsonObject, "total") ? jsonObject.get("total").getAsInt() : null) .build(); } }
public Followers createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new Followers.Builder() .setHref( hasAndNotNull(jsonObject, "href") ? jsonObject.get("href").getAsString() : null) .setTotal( hasAndNotNull(jsonObject, "total") ? jsonObject.get("total").getAsInt() : null) .build(); } }
public Error createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new Error.Builder() .setStatus( hasAndNotNull(jsonObject, "status") ? jsonObject.get("status").getAsInt() : null) .setMessage( hasAndNotNull(jsonObject, "message") ? jsonObject.get("message").getAsString() : null) .build(); } }
public AuthenticationError createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new AuthenticationError.Builder() .setError( hasAndNotNull(jsonObject, "error") ? jsonObject.get("error").getAsString() : null) .setError_description( hasAndNotNull(jsonObject, "error_description") ? jsonObject.get("error_description").getAsString() : null) .build(); } }
public Copyright createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new Copyright.Builder() .setText( hasAndNotNull(jsonObject, "text") ? jsonObject.get("text").getAsString() : null) .setType( hasAndNotNull(jsonObject, "type") ? CopyrightType.keyOf( jsonObject.get("type").getAsString().toLowerCase()) : null) .build(); } }
public Image createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new Image.Builder() .setHeight( hasAndNotNull(jsonObject, "height") ? jsonObject.get("height").getAsInt() : null) .setUrl( hasAndNotNull(jsonObject, "url") ? jsonObject.get("url").getAsString() : null) .setWidth( hasAndNotNull(jsonObject, "width") ? jsonObject.get("width").getAsInt() : null) .build(); } }
public ClientCredentials createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new ClientCredentials.Builder() .setAccessToken( hasAndNotNull(jsonObject, "access_token") ? jsonObject.get("access_token").getAsString() : null) .setTokenType( hasAndNotNull(jsonObject, "token_type") ? jsonObject.get("token_type").getAsString() : null) .setExpiresIn( hasAndNotNull(jsonObject, "expires_in") ? jsonObject.get("expires_in").getAsInt() : null) .build(); } }
public FeaturedPlaylists createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new FeaturedPlaylists.Builder() .setMessage( hasAndNotNull(jsonObject, "message") ? jsonObject.get("message").getAsString() : null) .setPlaylists( hasAndNotNull(jsonObject, "playlists") ? new PlaylistSimplified.JsonUtil().createModelObjectPaging( jsonObject.getAsJsonObject("playlists")) : null) .build(); } }
public AudioAnalysisMeasure createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new AudioAnalysisMeasure.Builder() .setConfidence( hasAndNotNull(jsonObject, "confidence") ? jsonObject.get("confidence").getAsFloat() : null) .setDuration( hasAndNotNull(jsonObject, "duration") ? jsonObject.get("duration").getAsFloat() : null) .setStart( hasAndNotNull(jsonObject, "start") ? jsonObject.get("start").getAsFloat() : null) .build(); } }
public Recommendations createModelObject(JsonObject jsonObject) { if (jsonObject == null || jsonObject.isJsonNull()) { return null; } return new Recommendations.Builder() .setSeeds( hasAndNotNull(jsonObject, "seeds") ? new RecommendationsSeed.JsonUtil().createModelObjectArray( jsonObject.getAsJsonArray("seeds")) : null) .setTracks( hasAndNotNull(jsonObject, "tracks") ? new TrackSimplified.JsonUtil().createModelObjectArray( jsonObject.getAsJsonArray("tracks")) : null) .build(); } }