Japan's Supreme Court has upheld a law that effectively requires transgender people to be sterilized before they can have their gender changed on official documents.

The court said the law is constitutional because it was meant to reduce confusion in families and society, but also acknowledged that it restricts freedom.

The unanimous decision rejected an appeal by Takakito Usui, a transgender man who said forced sterilization violates the right to self-determination and is unconstitutional.

TOKYO (AP) — Japan's Supreme Court has upheld a law that effectively requires transgender people to be sterilized before they can have their gender changed on official documents.

The court said the law is constitutional because it was meant to reduce confusion in families and society. But it acknowledged that it restricts freedom and could become out of step with changing social values.

The 2004 law states that people wishing to register a gender change must have their original reproductive organs, including testes or ovaries, removed and have a body that "appears to have parts that resemble the genital organs" of the gender they want to register.

In this May 7, 2017, file photo, participants smile as they march with a banner during the Tokyo Rainbow Pride parade celebrating the lesbian, gay, bisexual, and transgender (LGBT) community in Tokyo's Shibuya district. Shizuo Kambayashi/AP Photo The unanimous decision by a four-judge panel, published Thursday, rejected an appeal by Takakito Usui, a transgender man who said forced sterilization violates the right to self-determination and is unconstitutional.

Usui, 45, had appealed to the top court after he unsuccessfully requested lower courts to grant him legal recognition as male without having his female reproductive glands surgically removed.

Despite the unanimous decision, presiding justice Mamoru Miura joined another justice in saying that while the law may not violate the constitution, "doubts are undeniably emerging," according to Usui's lawyer, Tomoyasu Oyama.

Read more: Alexandria Ocasio-Cortez called into a Twitch stream of Donkey Kong 64 to help raise money for transgender kids

The two judges proposed regular reviews of the law and appropriate measures "from the viewpoint of respect for personality and individuality," according to Japanese media reports.

The Supreme Court decision ended Usui's legal battle, but he and his lawyer said the opinions in the ruling left them with hope.

"I think the ruling could lead to a next step," Usui told a news conference. "I hope to find what constitutes a family of my own that does not fit the traditional mold."

Participants wave as they march during the Tokyo Rainbow Pride parade celebrating the lesbian, gay, bisexual, and transgender (LGBT) community in Tokyo's Shibuya district, Sunday, May 7, 2017. Shizuo Kambayashi/AP Photo Human Rights Watch said the Supreme Court ruling was "incompatible with international human rights standards, goes against the times and deviates far from best global practices." The New York-based group said the ruling tolerates grave human rights violations against transgender people.

There is a growing awareness of sexual diversity in Japan, but it is often superficial and generally limited to the entertainment industry. In a country where pressure for conformity is strong, many LGBT people hide their sexuality even from their families because of a fear of prejudice at home, school or work.

Read more: A high school assistant principal is accused of harassing a transgender student over his choice of bathrooms

Japan does not legally recognize same-sex marriages. As LGBT rights awareness has gradually grown in recent years, some municipalities have begun issuing partnership certificates to ease problems in renting apartments and other areas, but they are not legally binding.

Lawmakers in the conservative ruling party have repeatedly come under fire for making discriminatory remarks about LGBT people. Earlier this year, Katsuei Hirasawa, a veteran lawmaker, was widely criticized for saying that "a nation would collapse" if everyone became LGBT.

Last year, another ruling party lawmaker, Mio Sugita, was condemned after saying in a magazine that the government shouldn't use tax money for LGBT rights because same-sex couples aren't "productive."