Merge pull request #1124 from recursiveribbons/remove-json-dependency
Remove dependency on org.json:json
This commit is contained in:
commit
1ec2a5103b
6
pom.xml
6
pom.xml
@ -72,7 +72,6 @@
|
|||||||
<mockitojupiter.version>4.8.1</mockitojupiter.version>
|
<mockitojupiter.version>4.8.1</mockitojupiter.version>
|
||||||
<jacksonanotation.version>2.14.0</jacksonanotation.version>
|
<jacksonanotation.version>2.14.0</jacksonanotation.version>
|
||||||
<jackson.version>2.14.0</jackson.version>
|
<jackson.version>2.14.0</jackson.version>
|
||||||
<json.version>20220924</json.version>
|
|
||||||
<slf4j.version>2.0.3</slf4j.version>
|
<slf4j.version>2.0.3</slf4j.version>
|
||||||
<jakarta.annotation.version>2.1.1</jakarta.annotation.version>
|
<jakarta.annotation.version>2.1.1</jakarta.annotation.version>
|
||||||
<lombok.version>1.18.24</lombok.version>
|
<lombok.version>1.18.24</lombok.version>
|
||||||
@ -135,11 +134,6 @@
|
|||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>${slf4j.version}</version>
|
<version>${slf4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<version>${json.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- Included to enforce common version-->
|
<!-- Included to enforce common version-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.annotation</groupId>
|
<groupId>jakarta.annotation</groupId>
|
||||||
|
@ -3,7 +3,6 @@ package org.telegram.abilitybots.api.objects;
|
|||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import org.json.JSONPropertyIgnore;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -90,10 +90,6 @@
|
|||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package org.telegram.telegrambots.meta.exceptions;
|
package org.telegram.telegrambots.meta.exceptions;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
import org.telegram.telegrambots.meta.api.objects.ApiResponse;
|
||||||
@ -48,20 +47,7 @@ public class TelegramApiRequestException extends TelegramApiException {
|
|||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TelegramApiRequestException(String message, JSONObject object) {
|
public TelegramApiRequestException(String message, ApiResponse<?> response) {
|
||||||
super(message);
|
|
||||||
apiResponse = object.getString(ERRORDESCRIPTIONFIELD);
|
|
||||||
errorCode = object.getInt(ERRORCODEFIELD);
|
|
||||||
if (object.has(PARAMETERSFIELD)) {
|
|
||||||
try {
|
|
||||||
parameters = OBJECT_MAPPER.readValue(object.getJSONObject(PARAMETERSFIELD).toString(), ResponseParameters.class);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TelegramApiRequestException(String message, ApiResponse response) {
|
|
||||||
super(message);
|
super(message);
|
||||||
apiResponse = response.getErrorDescription();
|
apiResponse = response.getErrorDescription();
|
||||||
errorCode = response.getErrorCode();
|
errorCode = response.getErrorCode();
|
||||||
|
@ -152,10 +152,6 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
|
@ -8,7 +8,6 @@ import org.apache.http.entity.ContentType;
|
|||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||||
@ -256,13 +255,9 @@ public class DefaultBotSession implements BotSession {
|
|||||||
lock.wait(500);
|
lock.wait(500);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
List<Update> updates = request.deserializeResponse(responseContent);
|
||||||
List<Update> updates = request.deserializeResponse(responseContent);
|
backOff.reset();
|
||||||
backOff.reset();
|
return updates;
|
||||||
return updates;
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Error deserializing update: " + responseContent, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (SocketException | InvalidObjectException | TelegramApiRequestException e) {
|
} catch (SocketException | InvalidObjectException | TelegramApiRequestException e) {
|
||||||
log.error(e.getLocalizedMessage(), e);
|
log.error(e.getLocalizedMessage(), e);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.telegram.telegrambots.util;
|
package org.telegram.telegrambots.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
@ -9,8 +11,6 @@ import org.apache.http.entity.ContentType;
|
|||||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.telegram.telegrambots.Constants;
|
import org.telegram.telegrambots.Constants;
|
||||||
import org.telegram.telegrambots.bots.DefaultAbsSender;
|
import org.telegram.telegrambots.bots.DefaultAbsSender;
|
||||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||||
@ -29,6 +29,7 @@ import static org.telegram.telegrambots.Constants.SOCKET_TIMEOUT;
|
|||||||
|
|
||||||
public final class WebhookUtils {
|
public final class WebhookUtils {
|
||||||
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
|
private static final ContentType TEXT_PLAIN_CONTENT_TYPE = ContentType.create("text/plain", StandardCharsets.UTF_8);
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
private WebhookUtils() {
|
private WebhookUtils() {
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ public final class WebhookUtils {
|
|||||||
builder.addTextBody(SetWebhook.MAXCONNECTIONS_FIELD, setWebhook.getMaxConnections().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
builder.addTextBody(SetWebhook.MAXCONNECTIONS_FIELD, setWebhook.getMaxConnections().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
if (setWebhook.getAllowedUpdates() != null) {
|
if (setWebhook.getAllowedUpdates() != null) {
|
||||||
builder.addTextBody(SetWebhook.ALLOWEDUPDATES_FIELD, new JSONArray(setWebhook.getAllowedUpdates()).toString(), TEXT_PLAIN_CONTENT_TYPE);
|
builder.addTextBody(SetWebhook.ALLOWEDUPDATES_FIELD, objectMapper.writeValueAsString(setWebhook.getAllowedUpdates()), TEXT_PLAIN_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
if (setWebhook.getIpAddress() != null) {
|
if (setWebhook.getIpAddress() != null) {
|
||||||
builder.addTextBody(SetWebhook.IPADDRESS_FIELD, setWebhook.getIpAddress(), TEXT_PLAIN_CONTENT_TYPE);
|
builder.addTextBody(SetWebhook.IPADDRESS_FIELD, setWebhook.getIpAddress(), TEXT_PLAIN_CONTENT_TYPE);
|
||||||
@ -95,7 +96,7 @@ public final class WebhookUtils {
|
|||||||
throw new TelegramApiRequestException("Error setting webhook:" + responseContent);
|
throw new TelegramApiRequestException("Error setting webhook:" + responseContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new TelegramApiRequestException("Error deserializing setWebhook method response", e);
|
throw new TelegramApiRequestException("Error deserializing setWebhook method response", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new TelegramApiRequestException("Error executing setWebook method", e);
|
throw new TelegramApiRequestException("Error executing setWebook method", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user