The box office recently played witness to an ultimate irony, as revered American author J.D. Salinger — who famously refused to allow any of his works, including his seminal masterpiece “The Catcher in the Rye,” to be adapted into feature films — served as the focal point for “Rebel in the Rye,” the directorial feature film debut of talented screenwriter Danny Strong.

The biopic film isn’t perfect and, in more than a few instances, falls into the trappings that you may have feared might come to fruition the moment you learned of its unimaginative title. Despite its shortcomings, “Rebel” pushes forward with an earnestness Salinger would have admired, and results in an homage to an American literary icon that even Salinger, who so hated publicity that he opted to live his post-“Catcher” life in a secluded cabin in New Hampshire, might have enjoyed.

Mercifully, “Rebel” forgoes dallying through Salinger’s childhood, and instead skips ahead to 1939, when a 20-year-old Salinger (a galvanizing Nicholas Hoult) convinces his supportive mother (Hope Davis) and stern, old-fashioned father (Victor Garber) to allow him to enroll at New York University and pursue his all-consuming dream of becoming a published creative writer. There, he is taken under the wing of “Dead Poets Society”-esque creative writing professor Whit Burnett (Kevin Spacey, in a delightfully heartwarming turn), who sees past Salinger’s wiseacre demeanor and recognizes that his newest student has unlimited potential — if he’s willing to persevere through the inevitable rejections authors must endure.

For the stubborn though eager Salinger, hardships abound in a myriad of ways outside of rejection letters: getting drafted for World War II; learning via newspaper headlines that his sweetheart Oona O’Neill (Zoey Deutch) left him for Charlie Chaplin; barely surviving the Battle of Normandy; and combatting both his post-traumatic stress disorder and his father’s lingering disapproval upon his return home.

Through all the adversity he faces, he remains determined to continue cultivating the story of Holden Caulfield. And even as his book “Catcher in the Rye” becomes a groundbreaking success that the public adores, it brings with it a level of fame and publicity that the reclusive Salinger maligns and struggles to reconcile.

I’ve learned to be wary of contemporary biopics, as they often feel as though they’re being suffocated by their insistence on covering every footnote of the subject’s life. Unfortunately, “Rebel” isn’t entirely innocent of this crime. Though every plot beat feels essential to understanding who Salinger was, not all of them delve as deeply into the circumstances or the emotional stakes as they should.

But for any scene that fails to ring true, there’s three that will have you smiling, enchanted by the absorbing window into Salinger’s unique mind that Strong has crafted. Hoult’s energetic approach to this enigmatic character is infectious, and watching his Salinger translate his discomfort with the world into his unapologetic writing is a joy to watch.

Both Hoult and the film itself are undoubtedly at their best when he’s paired with Spacey. I defy you to watch Spacey’s Burnett encourage a young Salinger to hone his craft and challenge him to make Holden Caulfield the central character of his first full-length novel without reminiscing fondly about the teachers that pulled your best work out of you. And, like Spacey, much of the supporting cast, particularly Sarah Paulson as Salinger’s literary agent, seem excited to be involved in a tribute to Salinger, and buoy the material with their enthusiasm.

Admittedly, “Rebel” (which is rated PG-13) could have used one more lap through the editing room (it clocks out at 110 minutes). But thanks to Strong’s smart direction, “Rebel’s” nearly two hours never devolve into anything less than watchable and is sometimes, much like Salinger’s writing, genuinely inspiring.