From d749fdee3a3df14e25a4864ec2cf72038c3b091d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 22 Sep 2017 17:36:01 +0300 Subject: api: inject correct json mapper --- juick-api/src/main/java/com/juick/api/TGBot.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'juick-api/src/main/java/com') diff --git a/juick-api/src/main/java/com/juick/api/TGBot.java b/juick-api/src/main/java/com/juick/api/TGBot.java index 72097154..aa912b29 100644 --- a/juick-api/src/main/java/com/juick/api/TGBot.java +++ b/juick-api/src/main/java/com/juick/api/TGBot.java @@ -58,7 +58,6 @@ public class TGBot extends TextWebSocketHandler { private static final Logger logger = LoggerFactory.getLogger(TGBot.class); private TelegramBot bot; - private ObjectMapper ms; @Value("${telegram_token}") private String telegramToken; @@ -68,6 +67,8 @@ public class TGBot extends TextWebSocketHandler { private MessagesService messagesService; @Inject static WebSocketConnectionManager connectionManager; + @Inject + private ObjectMapper jsonMapper; private WebSocketSession session; @@ -78,10 +79,6 @@ public class TGBot extends TextWebSocketHandler { return; } bot = TelegramBotAdapter.build(telegramToken); - ms = new ObjectMapper(); - ms.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); - ms.setSerializationInclusion(JsonInclude.Include.NON_NULL); - ms.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); try { SetWebhook webhook = new SetWebhook().url("https://api.juick.com/tlgmbtwbhk"); if (!bot.execute(webhook).isOk()) { @@ -114,10 +111,10 @@ public class TGBot extends TextWebSocketHandler { @Override protected void handleTextMessage(WebSocketSession session, TextMessage text) throws Exception { - com.juick.Message jmsg = ms.readValue(text.asBytes(), com.juick.Message.class); + com.juick.Message jmsg = jsonMapper.readValue(text.asBytes(), com.juick.Message.class); if (logger.isInfoEnabled()) // prevent writeValueAsString execution if logger disabled - logger.info("got jmsg: {}", ms.writeValueAsString(jmsg)); + logger.info("got jmsg: {}", jsonMapper.writeValueAsString(jmsg)); String msgUrl = formatUrl(jmsg); if (jmsg.getRid() == 0) { -- cgit v1.2.3