I won't get into the construction of your sentence, but try to address your main concern - When should we use prepositions at the end of the sentence. Firstly, the term for this is 'terminal prepositions'.
Well, it has been a moot point among grammarians. I too had this question in past and it was unclear before I referred to several authentic sources. Most of the sources you find on the Internet and grammar books say that terminal prepositions are perfectly appropriate to end the sentence with! :)
In fact, avoiding terminal prepositions in some sentences make them weird. Compare...
Who were you talking to?
To whom were you talking?
The latter looks over-formal.
So, use them if the sentence looks natural to you and if it's not necessary, avoid it.
The source used for this answer is the video Ask the Editor from Merriam Webster.
As oerkelens says, The reference to the class GenericClass does not specify of what type the saved object has to be. looks natural here.