Переход на Gson вместо непонятной Json библиотеки
This commit is contained in:
parent
c50ce8cd40
commit
a92d71ef3e
6
pom.xml
6
pom.xml
@ -32,7 +32,6 @@
|
|||||||
<gson.ver>2.8.5</gson.ver>
|
<gson.ver>2.8.5</gson.ver>
|
||||||
<vksdk.ver>0.5.13-SNAPSHOT</vksdk.ver>
|
<vksdk.ver>0.5.13-SNAPSHOT</vksdk.ver>
|
||||||
<log4j.ver>1.2.17</log4j.ver>
|
<log4j.ver>1.2.17</log4j.ver>
|
||||||
<json.ver>20180813</json.ver>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -51,11 +50,6 @@
|
|||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.ver}</version>
|
<version>${log4j.ver}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<version>${json.ver}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -20,7 +20,7 @@ public class MailSubscriber implements EventSubscribe<JsonObject>, EventDistribu
|
|||||||
private MailService mailService;
|
private MailService mailService;
|
||||||
|
|
||||||
private Set<Integer> admins = new HashSet<>();
|
private Set<Integer> admins = new HashSet<>();
|
||||||
private Map<String, EventSubscribe> eventDistributionMap = new HashMap<>();
|
private Map<String, EventSubscribe<Message>> eventDistributionMap = new HashMap<>();
|
||||||
|
|
||||||
public MailSubscriber(EventDistributable eventDistributable, MailService mailService) {
|
public MailSubscriber(EventDistributable eventDistributable, MailService mailService) {
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package org.sadtech.vkbot.core.distribution.impl;
|
package org.sadtech.vkbot.core.distribution.impl;
|
||||||
|
|
||||||
|
import com.vk.api.sdk.objects.messages.Message;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
||||||
import org.sadtech.vkbot.core.entity.Mail;
|
|
||||||
import org.sadtech.vkbot.core.service.handlers.MailService;
|
import org.sadtech.vkbot.core.service.handlers.MailService;
|
||||||
|
|
||||||
public class TerminalSubscriber implements EventSubscribe<Mail> {
|
public class TerminalSubscriber implements EventSubscribe<Message> {
|
||||||
|
|
||||||
public static final Logger log = Logger.getLogger(TerminalSubscriber.class);
|
public static final Logger log = Logger.getLogger(TerminalSubscriber.class);
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ public class TerminalSubscriber implements EventSubscribe<Mail> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Mail object) {
|
public void update(Message object) {
|
||||||
log.info("Сообщение отправленно на добавление в репозиторий команд");
|
log.info("Сообщение отправленно на добавление в репозиторий команд");
|
||||||
mailService.add(object);
|
mailService.add(object);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.sadtech.vkbot.core.keyboard;
|
package org.sadtech.vkbot.core.keyboard;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
public class ButtonKeyBoard {
|
public class ButtonKeyBoard {
|
||||||
|
|
||||||
@ -20,18 +20,18 @@ public class ButtonKeyBoard {
|
|||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getButton() {
|
public JsonObject getButton() {
|
||||||
JSONObject newButton = new JSONObject();
|
JsonObject newButton = new JsonObject();
|
||||||
newButton.put("color", color.toString().toLowerCase());
|
newButton.addProperty("color", color.toString().toLowerCase());
|
||||||
newButton.put("action", generateAction());
|
newButton.add("action", generateAction());
|
||||||
return newButton;
|
return newButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject generateAction() {
|
private JsonObject generateAction() {
|
||||||
JSONObject action = new JSONObject();
|
JsonObject action = new JsonObject();
|
||||||
action.put("type", type);
|
action.addProperty("type", type);
|
||||||
action.put("payload", payload);
|
action.addProperty("payload", payload);
|
||||||
action.put("label", label);
|
action.addProperty("label", label);
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package org.sadtech.vkbot.core.keyboard;
|
package org.sadtech.vkbot.core.keyboard;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import com.google.gson.JsonArray;
|
||||||
import org.json.JSONObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -24,16 +24,16 @@ public class KeyBoard {
|
|||||||
this.oneTime = oneTime;
|
this.oneTime = oneTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getKeyboard() {
|
public JsonObject getKeyboard() {
|
||||||
JSONObject keyboard = new JSONObject();
|
JsonObject keyboard = new JsonObject();
|
||||||
keyboard.put("one_time", oneTime);
|
keyboard.addProperty("one_time", oneTime);
|
||||||
|
|
||||||
JSONArray menuLine = new JSONArray();
|
JsonArray menuLine = new JsonArray();
|
||||||
for (LineKeyBoard lineKeyboard : lineKeyBoards) {
|
for (LineKeyBoard lineKeyboard : lineKeyBoards) {
|
||||||
menuLine.put(lineKeyboard.getLine());
|
menuLine.add(lineKeyboard.getLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
keyboard.put("buttons", menuLine);
|
keyboard.add("buttons", menuLine);
|
||||||
return keyboard;
|
return keyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.sadtech.vkbot.core.keyboard;
|
package org.sadtech.vkbot.core.keyboard;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import com.google.gson.JsonArray;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,10 +17,10 @@ public class LineKeyBoard {
|
|||||||
this.buttonKeyBoards = buttonKeyBoards;
|
this.buttonKeyBoards = buttonKeyBoards;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONArray getLine() {
|
public JsonArray getLine() {
|
||||||
JSONArray line = new JSONArray();
|
JsonArray line = new JsonArray();
|
||||||
for (ButtonKeyBoard buttonKeyBoard : buttonKeyBoards) {
|
for (ButtonKeyBoard buttonKeyBoard : buttonKeyBoards) {
|
||||||
line.put(buttonKeyBoard.getButton());
|
line.add(buttonKeyBoard.getButton());
|
||||||
}
|
}
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user