Berliners knew what JFK was saying. It’s an urban legend that they thought he was talking about a jelly doughnut or whatever pastry.
Berliners do not call jelly donuts “Berliners”. They call them krapfen!
I understand there was a pastry called a “Berliner”, and although the proper way to say what he said would be without “ein”, Germans knew what he meant.

Yes, but this his how Muslims see them now.
When Carter went to Frankfurt, Jeff MacNelly drew him with his usual grin, saying, “Ich bin ein Frankfurter.”
Well, JFK didn’t give the same speech in Hamburg, did he? ;-)
Not really. Cities in Germany often have a noted food, for which the city is known. The name of the city, with an "er" tacked on the end refers to the food.
The US sometimes has an equivalent. "I am Danish" describes the country you were born in. "I am a Danish" describes you as a pastry.
So JFK really did say "I am a jelly doughnut" when he addes the "ein" to the sentence. The Germans knew, though, what he meant.