-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from yvasyliev/TrackDataDeserializer_inifinite…
…_recursion_fix fixed infinite deserialization recursion
- Loading branch information
Showing
3 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 14 additions & 4 deletions
18
src/main/java/api/deezer/deserializers/TrackDataDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
package api.deezer.deserializers; | ||
|
||
import api.deezer.objects.Track; | ||
import api.deezer.objects.data.TrackData; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
public class TrackDataDeserializer implements JsonDeserializer<TrackData> { | ||
@Override | ||
public TrackData deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | ||
boolean isFalse = jsonElement.isJsonPrimitive() | ||
&& jsonElement.getAsJsonPrimitive().isBoolean() | ||
&& jsonElement.getAsBoolean(); | ||
return isFalse ? null : jsonDeserializationContext.deserialize(jsonElement, type); | ||
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isBoolean() && !jsonElement.getAsBoolean()) { | ||
return null; | ||
} | ||
|
||
JsonObject jsonObject = jsonElement.getAsJsonObject(); | ||
TrackData trackData = new TrackData(); | ||
trackData.setNext(jsonObject.get("next").getAsString()); | ||
trackData.setTotal(jsonObject.get("total").getAsInt()); | ||
trackData.setData(jsonDeserializationContext.deserialize(jsonObject.get("data"), TypeToken.getParameterized(List.class, Track.class).getType())); | ||
return trackData; | ||
} | ||
} |