I have the following Controllers (in diagram) which Call the Static method to get the data. As I am going to use the data at many other pages , I dont want to requets for the data again and again. That’s why I am checking whether data is null and then returning the value appropriately.
private static IEnumerable<MovieDetails> GetJsonData(string jsonRequestURL)
{
try
{
using (var wc = new WebClient())
{
var json = wc.DownloadString(jsonRequestURL);
var rootObj = JsonConvert.DeserializeObject<MoviesListRootObject>(json);
var responseObject = rootObj.movieResponse;
var movieDetails = responseObject.Select(movieDetail =>
new MovieDetails
{
Description = movieDetail.description,
MovieURI = movieDetail.formats.res150p,
Thumbnail = movieDetail.image,
Title = movieDetail.title,
ID = movieDetail.id
});
return movieDetails;
}
}
catch (Exception exception)
{
//Error Handling
}
}
This is perfect till the time, GetJsonData is Desrializng to only One type(Currently MoviesListRootObject what If I want to ConvertTo AnotherType of Root object ex: FeaturedlistRootObject).
But how in the same method I can Desirialing to other types?

Are generics the only option or there exist some better design/feature I can use (not sure how helpful dynamic will be)?
Again, if I am only left with generics, can I avoid writing code based on different types?
There seem to be two parts of your code that can change:
MoviesListRootObject) and the type of the result (e.g.IEnumerable<MovieDetails>)Generics are the perfect solution for #1, but they won’t help you much with #2, you need some other mechanism for that. Depending on the structure of your code, the best solution for #2 may differ. I think you pretty much have two choices here:
Choice 1 could look something like this:
This way, the general code for downloading JSON data is separated from the specific code for downloading movie details.