diff --git a/linebot/models/flex_message.py b/linebot/models/flex_message.py index afccc3ef5..bd951695b 100644 --- a/linebot/models/flex_message.py +++ b/linebot/models/flex_message.py @@ -109,7 +109,12 @@ def __init__(self, size=None, direction=None, header=None, hero=None, self.size = size self.direction = direction self.header = self.get_or_new_from_json_dict(header, BoxComponent) - self.hero = self.get_or_new_from_json_dict(hero, ImageComponent) + self.hero = self.get_or_new_from_json_dict_with_types( + hero, { + 'image': ImageComponent, + 'box': BoxComponent + } + ) self.body = self.get_or_new_from_json_dict(body, BoxComponent) self.footer = self.get_or_new_from_json_dict(footer, BoxComponent) self.styles = self.get_or_new_from_json_dict(styles, BubbleStyle) diff --git a/tests/models/test_flex_message.py b/tests/models/test_flex_message.py index ad752fcdc..9fe7c293f 100644 --- a/tests/models/test_flex_message.py +++ b/tests/models/test_flex_message.py @@ -61,8 +61,6 @@ def test_bubble_container(self): 'header': BoxComponent(layout='vertical', contents=[TextComponent(text='Header text')]), - 'hero': - ImageComponent(uri='https://example.com/flex/images/image.jpg'), 'body': BoxComponent(layout='vertical', contents=[TextComponent(text='Body text')]), @@ -79,10 +77,17 @@ def test_bubble_container(self): separator_color='#00ffff') ) } - self.assertEqual( - self.serialize_as_dict(arg, type=self.BUBBLE), - BubbleContainer(**arg).as_json_dict() - ) + heros = [ + ImageComponent(uri='https://example.com/flex/images/image.jpg'), + BoxComponent(layout='vertical', + contents=[TextComponent(text='Body text')]), + ] + for hero in heros: + arg['hero'] = hero + self.assertEqual( + self.serialize_as_dict(arg, type=self.BUBBLE), + BubbleContainer(**arg).as_json_dict() + ) def test_bubble_style(self): arg = {