-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
393 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package coresearch.cvurl.io.mapper; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* Class that describes type with generics. Used as parameter to some of {@link coresearch.cvurl.io.request.Request} | ||
* methods to provide ability to parse response to body to class with generics. | ||
* Usage example: <br/> | ||
* {@code cvurl.get(url).asObject(new BodyType<List<Users>() {});} <br/> | ||
* this code snippet would parse response body to {@code List<User>} | ||
*/ | ||
public abstract class BodyType<T> { | ||
|
||
private static final String ERROR_MESSAGE = "Type should be direct child type of BodyType"; | ||
|
||
private Type type; | ||
|
||
protected BodyType() { | ||
ParameterizedType superclass = (ParameterizedType) this.getClass().getGenericSuperclass(); | ||
if (superclass.getRawType() != BodyType.class) { | ||
throw new IllegalStateException(ERROR_MESSAGE); | ||
} | ||
this.type = superclass.getActualTypeArguments()[0]; | ||
} | ||
|
||
/** | ||
* @return actual type | ||
*/ | ||
public Type getType() { | ||
return type; | ||
} | ||
} |
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
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
Oops, something went wrong.