Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use telegram types for automatic binding in SpringBoot. #1420

Open
Aiden-777 opened this issue Aug 23, 2024 · 2 comments
Open

Unable to use telegram types for automatic binding in SpringBoot. #1420

Aiden-777 opened this issue Aug 23, 2024 · 2 comments

Comments

@Aiden-777
Copy link

Describe the bug
version: v7.9.1
Unable to use telegram types for automatic binding in SpringBoot.
On the contrary, it can work normally in lower versions, such as: 6.8.0
I tried using multiple versions of SpringBoot3, but it still didn't work
I hope anyone with experience can give me some help.

@Component
@ConfigurationProperties(prefix = "exchange-bot")
@Validated
@Getter
@Setter
@ToString
@Slf4j
public class ExchangeBotProperties {
    
    /**
     * Command menu
     */
    private List<BotCommand> commands;
}
exchange-bot:  
  commands:
    - command: /start
      description: 💹start
    - command: /exchange
      description: 💹exchange

Error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target [Bindable@226b143b type = java.util.List<org.telegram.telegrambots.meta.api.objects.commands.BotCommand>, value = 'provided', annotations = array<Annotation>[[empty]], bindMethod = [null]] failed:

    Property: exchange-bot.commands[0].command
    Value: "/start"
    Origin: class path resource [application-bot.yml] - 29:16
    Reason: The elements [exchange-bot.commands[0].command,exchange-bot.commands[0].description,exchange-bot.commands[1].command,exchange-bot.commands[1].description,exchange-bot.commands[2].command,exchange-bot.commands[2].description,exchange-bot.commands[3].command,exchange-bot.commands[3].description,exchange-bot.commands[4].command,exchange-bot.commands[4].description] were left unbound.
    Property: exchange-bot.commands[0].description

Maven:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--<dependency>
            <groupId>org.telegram</groupId>
            <artifactId>telegrambots-springboot-longpolling-starter</artifactId>
            <version>${telegrambots.version}</version>
        </dependency>-->
        <dependency>
            <groupId>org.telegram</groupId>
            <artifactId>telegrambots-client</artifactId>
            <version>${telegrambots.version}</version>
        </dependency>
        <dependency>
            <groupId>org.telegram</groupId>
            <artifactId>telegrambots-abilities</artifactId>
            <version>${telegrambots.version}</version>
        </dependency>
    </dependencies>

Before

@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor(force = true)
@AllArgsConstructor
@Builder
public class BotCommand implements BotApiObject, Validable

Now

@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
public class BotCommand implements BotApiObject, Validable
@rubenlagus
Copy link
Owner

The only different here is the removal of the no-arg constructor that was forced in these case for backward compatibility with previous version but was warned that it was only a temporary option and bound to be removed in next major version (aka v7).

As a quick workaround, you should be able to extend the BotCommand class in your project and add a single no-arg constructor that calls the parent constructor, or to implement the constructor you need and use the ConstructorBinding annotation instead of fields binding.

@Aiden-777
Copy link
Author

The only different here is the removal of the no-arg constructor that was forced in these case for backward compatibility with previous version but was warned that it was only a temporary option and bound to be removed in next major version (aka v7).

As a quick workaround, you should be able to extend the BotCommand class in your project and add a single no-arg constructor that calls the parent constructor, or to implement the constructor you need and use the ConstructorBinding annotation instead of fields binding.

I have temporarily given up on updating to the new version. The project contains not only BotCommand but also many other types that need to be customized in the configuration file. I hope that in the future, the project team will consider reintroducing the no-argument constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants