although a lot of adaptations skip over this and sanitise it to the point where the message is apparently meant to read "you'll be forgiven for being born wrong, if you turn out thin and white and pretty!" - there's a lot going on in the original. For one thing, most adaptations present him as a wild animal, but the Ugly Duckling is born into captivity, into a society that mimics upper-class pretensions, which is why he's declared 'ugly'. His mother is loving and very generous at first - hatching him despite the inconvenient incubation period, and defending him firmly - but after the other domestic animals (including a higher-class dominant one) point out what a burden he is, she turns on her child. Previously, she genuinely appeared to like him.
And a thing that's missed, while kid's abridged adaptations miss out on the rest of the point, is that the Ugly Duckling decides he can't live like this and leaves the farmyard; he goes into the wild himself. In the various passages in which people try to keep him as a pet, or a duck, it's hammered home again and again that this does not make a good pet. there is nothing in him that suits being a domestic animal.
one of the particular parts that makes you go "sweet jesus, hans christian andersen" is where the wild geese rock up and are nice to the young swan, not quite recognising him as a swan but saying they're pretty into whatever weird vibe he has (is this a sort of queer recognition thing? we are told, explicitly, that the wild geese are both male, and they definitely say "you're so ugly it's hot - come with us" - given HCA, it might be) and then they're, you know, instantly shot dead. Because that's what happens to wild geese. They like your vibe and try to take you with them, and even offer to teach you how to flirt - and then you see exactly what happens to them. And then every encounter from there, from the old woman who attempts to keep him - a very satirical and funny passage - to the young family who genuinely attempt to save his life (but he's too fundamentally panicked and awkward to reciprocate their kindness, and explodes out of their house in a social catastrophe) the story hammers in: not only are you a terrible duck, but you just aren't MEANT to live with people. You're closer to the things they kill than the things they keep.
but yeah, adaptations miss this often: you have to go out into the wild to save your own life. you may die in the wild, and you WILL die where you are. nobody comes to save you - and nobody really could have, when you were younger - but ultimately, mate, you just aren't a very good pet. Of the list of "attributes of a domestic animal" you really suck, in detail, at all of them.
so it's very telling to me that the good ending is the one where he is a wild animal - but more importantly, a WILD SWAN.
Not killed. (like a wild goose).
but a secret third thing, that swans - of few creatures - get. they get admired and they get paid and they get LEFT ALONE. they have a position in relation to humanity, and it is BEING A LOVELY SWAN OVER THERE.
what a thing for a lonely heart to yearn for!