3. The Artist data source
3m

🎯 Your goal for this step:

Add a new method to the class to retrieve artist-specific data

Artist data tasks

Use the following artist ID when completing these tasks.

An artist ID
3GBPw9NK25X1Wt2OUvOwY3

Solution: The Artist data source

models/MappedArtist
package com.example.soundtracks.models;
import com.example.soundtracks.generated.types.Artist;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.JsonNode;
@JsonIgnoreProperties(ignoreUnknown = true)
public class MappedArtist extends Artist {
@JsonSetter("followers")
public void mapFollowers(JsonNode followersNode) {
this.setFollowers(followersNode.get("total").asInt());
}
}
datasources/SpotifyClient
// ... other SpotifyClient methods
public MappedArtist artistRequest(String artistId) {
System.out.println("I am making a request to the artists endpoint for " + artistId);
return client
.get()
.uri("/artists/{artist_id}", artistId)
.retrieve()
.body(MappedArtist.class);
}
Previous

Share your questions and comments about this lesson

This course is currently in

beta
. Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.