rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

missing type id property '@class' (for POJO property 'reply_markup') #625

Closed forever-drunk-programmer closed 5 years ago

forever-drunk-programmer commented 5 years ago

Hi! Got a exception, when try use InlineButton from telegram, sended via bot

version - 4.3 Error:

Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup]: missing type id property '@class' (for POJO property 'reply_markup')
 at [Source: (String)"{"ok":true,"result":{"message_id":97,"from":{"id":123,"is_bot":true,"first_name":"MyBot","username":"MyBot_bot"},"chat":{"id":321,"first_name":"Me","last_name":"Me","username":"Me","type":"private"},"date":1559825108,"text":"\u0438\u044e\u043d. test1\ntest2\ntest3\ntest4","entities":[{"offset":23,"length":38,"type":"bold"},{"offset":113,"length":9,"type":"bold"}]"[truncated 92 chars]; line: 1, column: 590] (through reference chain: org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse["result"]->org.telegram.telegrambots.meta.api.objects.Message["reply_markup"])

Code:

ArrayList<String> eventsStringList = new ArrayList<>();
events.forEach(event ->
    eventsStringList.add(event.presentation())
);
preparedMessage.enableMarkdown(true);
preparedMessage.setChatId(message.getChatId());
preparedMessage.setText(String.join("\n", eventsStringList));

InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> rowsInline = new ArrayList<>();
List<InlineKeyboardButton> rowInline = new ArrayList<>();
rowInline.add(new InlineKeyboardButton().setText("test1").setCallbackData("update_msg_text"));
rowsInline.add(rowInline);

markupInline.setKeyboard(rowsInline);

preparedMessage.setReplyMarkup(markupInline);
sendMessage(preparedMessage); //here will try/catch execute(preparedMessage)
Tyde commented 5 years ago

I encountered the same problem. When I downgraded to version 4.2, it seems to work.

ghost commented 5 years ago

Same, I downgraded to version 4.2 and now I don't have any problem.