I know that we can use both :
1: John gives Mary the book.
and 2: John gives the book to Mary.

Now I need to know which of these two sentences are wrong and why please , :

1: John gave a new coat of paint to the fence.
2: John gave the fence a new coat of paint.

Thank you