fix compilation problems

master
denys.konakhevych 6 years ago
parent 07b06455cf
commit 252a6abab2

@ -49,6 +49,7 @@ import com.omertron.themoviedbapi.tools.TmdbParameters;
import com.omertron.themoviedbapi.results.WrapperChanges; import com.omertron.themoviedbapi.results.WrapperChanges;
import com.omertron.themoviedbapi.results.WrapperGenericList; import com.omertron.themoviedbapi.results.WrapperGenericList;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -68,7 +69,7 @@ public class AbstractMethod {
protected final HttpTools httpTools; protected final HttpTools httpTools;
// Jackson JSON configuration // Jackson JSON configuration
protected static final ObjectMapper MAPPER = new ObjectMapper(); protected static final ObjectMapper MAPPER = new ObjectMapper();
private static final Map<Class, TypeReference> TYPE_REFS = new HashMap<>(); private static final Map<Class<? extends Serializable>, TypeReference<? extends WrapperGenericList<? extends Serializable>>> TYPE_REFS = new HashMap<>();
static { static {
TYPE_REFS.put(MovieBasic.class, new TypeReference<WrapperGenericList<MovieBasic>>() { TYPE_REFS.put(MovieBasic.class, new TypeReference<WrapperGenericList<MovieBasic>>() {
@ -124,9 +125,9 @@ public class AbstractMethod {
* @return * @return
* @throws MovieDbException * @throws MovieDbException
*/ */
protected static TypeReference getTypeReference(Class aClass) throws MovieDbException { protected static <T> TypeReference<? extends WrapperGenericList<T>> getTypeReference(Class<T> aClass) throws MovieDbException {
if (TYPE_REFS.containsKey(aClass)) { if (TYPE_REFS.containsKey(aClass)) {
return TYPE_REFS.get(aClass); return (TypeReference<? extends WrapperGenericList<T>>) TYPE_REFS.get(aClass);
} else { } else {
throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Class type reference for '" + aClass.getSimpleName() + "' not found!"); throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Class type reference for '" + aClass.getSimpleName() + "' not found!");
} }
@ -142,7 +143,7 @@ public class AbstractMethod {
* @return * @return
* @throws MovieDbException * @throws MovieDbException
*/ */
protected <T> List<T> processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { protected <T> List<T> processWrapperList(TypeReference<? extends WrapperGenericList<T>> typeRef, URL url, String errorMessageSuffix) throws MovieDbException {
WrapperGenericList<T> val = processWrapper(typeRef, url, errorMessageSuffix); WrapperGenericList<T> val = processWrapper(typeRef, url, errorMessageSuffix);
return val.getResults(); return val.getResults();
} }
@ -157,7 +158,7 @@ public class AbstractMethod {
* @return * @return
* @throws MovieDbException * @throws MovieDbException
*/ */
protected <T> WrapperGenericList<T> processWrapper(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { protected <T> WrapperGenericList<T> processWrapper(TypeReference<? extends WrapperGenericList<T>> typeRef, URL url, String errorMessageSuffix) throws MovieDbException {
String webpage = httpTools.getRequest(url); String webpage = httpTools.getRequest(url);
try { try {
// Due to type erasure, this doesn't work // Due to type erasure, this doesn't work

@ -113,7 +113,7 @@ public class TmdbPeople extends AbstractMethod {
String webpage = httpTools.getRequest(url); String webpage = httpTools.getRequest(url);
try { try {
TypeReference tr = new TypeReference<PersonCreditList<CreditMovieBasic>>() { TypeReference<PersonCreditList<CreditMovieBasic>> tr = new TypeReference<PersonCreditList<CreditMovieBasic>>() {
}; };
return MAPPER.readValue(webpage, tr); return MAPPER.readValue(webpage, tr);
} catch (IOException ex) { } catch (IOException ex) {
@ -144,7 +144,7 @@ public class TmdbPeople extends AbstractMethod {
String webpage = httpTools.getRequest(url); String webpage = httpTools.getRequest(url);
try { try {
TypeReference tr = new TypeReference<PersonCreditList<CreditTVBasic>>() { TypeReference<PersonCreditList<CreditTVBasic>> tr = new TypeReference<PersonCreditList<CreditTVBasic>>() {
}; };
return MAPPER.readValue(webpage, tr); return MAPPER.readValue(webpage, tr);
} catch (IOException ex) { } catch (IOException ex) {
@ -177,7 +177,7 @@ public class TmdbPeople extends AbstractMethod {
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(PersonCreditList.class, PersonCreditsMixIn.class); mapper.addMixIn(PersonCreditList.class, PersonCreditsMixIn.class);
TypeReference tr = new TypeReference<PersonCreditList<CreditBasic>>() { TypeReference<PersonCreditList<CreditBasic>> tr = new TypeReference<PersonCreditList<CreditBasic>>() {
}; };
return mapper.readValue(webpage, tr); return mapper.readValue(webpage, tr);
} catch (IOException ex) { } catch (IOException ex) {

Loading…
Cancel
Save