Permalink
Browse files

#15 Adding LastFmTrackListResponse which is capable of binding to emp…

…ty lists, and changing LastFmLovedTracksResponse so that it now wraps LastFmTrackListResponse rather than the LastFmTrackResponse previously used. This fixes NPE occuring when loved track list is empty
  • Loading branch information...
1 parent 2c1e416 commit 8f795b10932df9586bede1ae29c397cc0b196f24 @michaellavelle committed Jan 13, 2012
@@ -102,8 +102,7 @@ public LastFmProfile getUserProfile(String userName) {
return restTemplate
.getForObject(buildLastFmApiUrl(methodParameters),
- LastFmLovedTracksResponse.class).getNestedResponse().getNestedResponse()
- .getTracks();
+ LastFmLovedTracksResponse.class).getNestedResponse().getTracks();
}
@@ -18,12 +18,13 @@
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
+import org.springframework.social.lastfm.api.impl.json.lists.LastFmTrackListResponse;
/**
* @author Michael Lavelle
*/
@JsonIgnoreProperties(ignoreUnknown = true)
-public class LastFmLovedTracksResponse extends AbstractLastFmNestedResponse<LastFmTracksResponse>{
+public class LastFmLovedTracksResponse extends AbstractLastFmNestedResponse<LastFmTrackListResponse>{
public LastFmLovedTracksResponse() {
super("lovedtracks");
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.lastfm.api.impl.json.lists;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.springframework.social.lastfm.api.Shout;
+import org.springframework.social.lastfm.api.Track;
+
+/**
+ * @author Michael Lavelle
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class LastFmTrackListResponse {
+
+ private TrackListContainer trackListContainer;
+
+ @JsonCreator
+ public LastFmTrackListResponse() {
+ this.trackListContainer = new TrackListContainer(new ArrayList<Track>());
+ }
+
+
+ @JsonProperty("track")
+ public void setTrackListContainer(TrackListContainer trackListContainer) {
+ this.trackListContainer = trackListContainer;
+ }
+
+
+ public List<Track> getTracks() {
+ return trackListContainer.getTracks();
+ }
+
+
+}

0 comments on commit 8f795b1

Please sign in to comment.