Class JsonDeserializer


  • public final class JsonDeserializer
    extends Object
    Utility class for JSON response deserialization.


    Provides functionality to parse the JSON data returned by the remote API and map it into it's corresponding DTO. These DTO's will be wrapped into APIResponse<DTO> objects together with additional information like advanced error reports or pagination information. Note that the latter depends on the invoked remote route and will not always be available. Simple return types will not be mapped into a dedicated DTO class but will use the corresponding Java native data type. For example, query parameters, which are a simple collection of strings, will be mapped into a list of String whereas simple key/value paris will be returned as Map<String, String>.

    • Method Detail

      • mapQueryParameters

        public static APIResponse<List<String>> mapQueryParameters​(@Nonnull
                                                                   com.fasterxml.jackson.databind.JsonNode json)
                                                            throws APIException
        Maps the actual parameters returned by the various routes responsible for providing a list of available query parameters to be used for certain queryable requests.


        Note: Some routes will return the query parameters directly within the data node whereas for other routes the parameters may be located in a nested params sub-node. If such a nested node is present, the parameters will be parsed from this node. Otherwise the parameters will be parsed from the data node.

        Parameters:
        json - The full JSON as returned by the remote service, containing a list of query parameters in either the data node or a nested params sub-node
        Returns:
        Extended API response containing a list of query parameters parsed from the given JSON. The returned object typically doesn't contain any additional error and paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapFavorites

        public static APIResponse<List<String>> mapFavorites​(@Nonnull
                                                             com.fasterxml.jackson.databind.JsonNode json)
                                                      throws APIException
        Maps the actual favorites returned by the various routes responsible for adding, deleting and obtaining user favorites.


        Note: In case the user has no favorites it is possible that some routes will not return an empty, nested favorites sub-node but an empty data node instead. Such responses will be handled fail-safe by this method, resulting in response containing an empty list being returned.

        Parameters:
        json - The full JSON as returned by the remote service, containing a list of favorites within the favorites sub-node
        Returns:
        Extended API response containing a list of favorites parsed from the given JSON as well as optional, additional error information. The returned object typically doesn't contain any additional paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapSeriesHeader

        public static APIResponse<Map<String,String>> mapSeriesHeader​(@Nonnull
                                                                      com.fasterxml.jackson.databind.JsonNode json)
                                                               throws APIException
        Maps the header information for a specific series returned by the remote series HEAD route. The header information properties will be represented by the key/value pairs of the returned API responses data map.
        Parameters:
        json - The full JSON as returned by the remote service, containing key/value pairs of header information
        Returns:
        Map containing header information key/value pairs
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapSeriesSearchResult

        public static APIResponse<List<SeriesSearchResult>> mapSeriesSearchResult​(@Nonnull
                                                                                  com.fasterxml.jackson.databind.JsonNode json)
                                                                           throws APIException
        Maps the actual search results returned by the series search route.
        Parameters:
        json - The full JSON as returned by the remote service, containing a list of matching search results within the data node
        Returns:
        Extended API response containing a list of search results parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapSeries

        public static APIResponse<Series> mapSeries​(@Nonnull
                                                    com.fasterxml.jackson.databind.JsonNode json)
                                             throws APIException
        Maps the actual series data returned by the various routes responsible for fetching or filtering series.
        Parameters:
        json - The full JSON as returned by the remote service, containing the matching series information within the data node
        Returns:
        Extended API response containing the series data parsed from the given JSON as well as optional, additional error information. The returned object typically doesn't contain any additional paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapEpisode

        public static APIResponse<Episode> mapEpisode​(@Nonnull
                                                      com.fasterxml.jackson.databind.JsonNode json)
                                               throws APIException
        Maps the actual episode data of a specific episode returned by the episodes route.
        Parameters:
        json - The full JSON as returned by the remote service, containing the episode information within the data node
        Returns:
        Extended API response containing the episode data parsed from the given JSON as well as optional, additional error information. The returned object typically doesn't contain any additional paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapEpisodes

        public static APIResponse<List<Episode>> mapEpisodes​(@Nonnull
                                                             com.fasterxml.jackson.databind.JsonNode json)
                                                      throws APIException
        Maps the actual episode data returned by the various routes responsible for fetching and querying episodes.


        The remote API will only return 100 matching records at most. Additional records may be fetched by using the paging information which may be accessed via the returned API response object (see APIResponse.getLinks()).

        Parameters:
        json - The full JSON as returned by the remote service, containing a list of episode information within the data node
        Returns:
        Extended API response containing a list of episodes parsed from the given JSON as well as optional, additional error and paging information.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapLanguages

        public static APIResponse<List<Language>> mapLanguages​(@Nonnull
                                                               com.fasterxml.jackson.databind.JsonNode json)
                                                        throws APIException
        Maps the actual languages returned by the API route responsible for providing a list of available languages.
        Parameters:
        json - The full JSON as returned by the remote service, containing a list of available languages within the data node
        Returns:
        Extended API response containing a list of available languages parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapLanguage

        public static APIResponse<Language> mapLanguage​(@Nonnull
                                                        com.fasterxml.jackson.databind.JsonNode json)
                                                 throws APIException
        Maps the actual language data returned by the API route responsible for obtaining advanced information about a specific language.
        Parameters:
        json - The full JSON as returned by the remote service, containing the language information within the data node
        Returns:
        Extended API response containing the language data parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapMovie

        public static APIResponse<Movie> mapMovie​(@Nonnull
                                                  com.fasterxml.jackson.databind.JsonNode json)
                                           throws APIException
        Maps the actual movie data returned by the movies route.
        Parameters:
        json - The full JSON as returned by the remote service, containing the movie information within the data node
        Returns:
        Extended API response containing the movie data parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapMovieUpdates

        public static APIResponse<List<Long>> mapMovieUpdates​(@Nonnull
                                                              com.fasterxml.jackson.databind.JsonNode json)
                                                       throws APIException
        Maps the actual updated movies ID's returned by the movie updates route.


        Note: This seems to be the only route that doesn't return its content wrapped into a "data" node but into a "movies" node instead. In order to be able to reuse the general parsing logic this method will remap the content of the given JSON "movies" node into a new objects "data" node.

        Parameters:
        json - The full JSON as returned by the remote service, containing the updated movies ID's within the movies node
        Returns:
        Extended API response containing the updated movies ID's parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapActors

        public static APIResponse<List<Actor>> mapActors​(@Nonnull
                                                         com.fasterxml.jackson.databind.JsonNode json)
                                                  throws APIException
        Maps the actual actor data returned by the series actors route.
        Parameters:
        json - The full JSON as returned by the remote service, containing a list of actor information within the data node
        Returns:
        Extended API response containing a list of actors parsed from the given JSON as well as optional, additional error information. The returned object typically doesn't contain any additional paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapSeriesSummary

        public static APIResponse<SeriesSummary> mapSeriesSummary​(@Nonnull
                                                                  com.fasterxml.jackson.databind.JsonNode json)
                                                           throws APIException
        Maps the actual summary data returned by the series episode summary route.
        Parameters:
        json - The full JSON as returned by the remote service, containing the series episode summary information within the data node
        Returns:
        Extended API response containing the episode summary data parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapImageQueryParameters

        public static APIResponse<List<ImageQueryParameter>> mapImageQueryParameters​(@Nonnull
                                                                                     com.fasterxml.jackson.databind.JsonNode json)
                                                                              throws APIException
        Maps the actual parameters returned by the API route responsible for providing a list of available image query parameters.
        Parameters:
        json - The full JSON as returned by the remote service, containing a list of image query parameters within the data node
        Returns:
        Extended API response containing a list of image query parameters parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapSeriesImageSummary

        public static APIResponse<ImageSummary> mapSeriesImageSummary​(@Nonnull
                                                                      com.fasterxml.jackson.databind.JsonNode json)
                                                               throws APIException
        Maps the actual summary data returned by the series images route.
        Parameters:
        json - The full JSON as returned by the remote service, containing the series images information within the data node
        Returns:
        Extended API response containing the series images data parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapImages

        public static APIResponse<List<Image>> mapImages​(@Nonnull
                                                         com.fasterxml.jackson.databind.JsonNode json)
                                                  throws APIException
        Maps the actual image data returned by the queryable series images route.
        Parameters:
        json - The full JSON as returned by the remote service, containing a list of image information within the data node
        Returns:
        Extended API response containing a list of images parsed from the given JSON as well as optional, additional error information. The returned object typically doesn't contain any additional paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapUpdates

        public static APIResponse<Map<Long,Long>> mapUpdates​(@Nonnull
                                                             com.fasterxml.jackson.databind.JsonNode json)
                                                      throws APIException
        Maps the recently updated series data returned by the queryable updated route.


        The JSON data will be parsed into a map which keys represent the ID of the updated series while their the corresponding values represent the actual date/time of the last update as epoch time.

        Parameters:
        json - The full JSON as returned by the remote service, containing key/value pairs of recently updated series within the data node
        Returns:
        Extended API response containing a map of last updated series parsed from the given JSON as well as optional, additional error information. The returned object typically doesn't contain any additional paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapRatings

        public static APIResponse<List<Rating>> mapRatings​(@Nonnull
                                                           com.fasterxml.jackson.databind.JsonNode json)
                                                    throws APIException
        Maps the actual ratings returned by the various routes responsible for adding, querying and fetching user ratings.
        Parameters:
        json - The full JSON as returned by the remote service, containing a list of rating information within the data node
        Returns:
        Extended API response containing a list of ratings parsed from the given JSON as well as optional, additional paging information. The returned object typically doesn't contain any additional error information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object
      • mapUser

        public static APIResponse<User> mapUser​(@Nonnull
                                                com.fasterxml.jackson.databind.JsonNode json)
                                         throws APIException
        Maps the actual user data returned by the user route.
        Parameters:
        json - The full JSON as returned by the remote service, containing the user information within the data node
        Returns:
        Extended API response containing the user data parsed from the given JSON. The returned object typically doesn't contain any additional error or paging information as such data is usually not available for remote routes used in conjunction with this method.
        Throws:
        APIException - If an IO error occurred during the deserialization of the given JSON object