Skip to content

Commit

Permalink
fix: reading json array from web response!
Browse files Browse the repository at this point in the history
  • Loading branch information
cooffeeRequired committed Mar 17, 2024
1 parent 3323c70 commit 1d97d4a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cz.coffee</groupId>
<artifactId>skJson</artifactId>
<version>3.0.5</version>
<version>3.0.6</version>
<packaging>jar</packaging>

<name>SkJson</name>
Expand All @@ -26,8 +26,6 @@
<url>https://repo.bytecode.space/repository/maven-public/</url>
</pluginRepository>
</pluginRepositories>


<repositories>
<repository>
<id>jitpack.io</id>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cz/coffee/skjson/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ static <T> JsonElement assign(T object) {
* @return the t
*/
public static <T> T from(JsonElement json) {
if (json == null || json.isJsonArray() || json.isJsonNull()) return null;
if (json == null || json.isJsonNull()) return null;
else if (json.isJsonPrimitive()) return ParserUtil.jsonToType(json);
else if (json.isJsonArray()) return (T) json;
final JsonElement finalJson = json.deepCopy();
Class<?> clazz = null;
String potentialClass = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.ws.rs.core.UriBuilder;
import java.lang.reflect.Field;
import java.net.URI;
import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -121,7 +122,6 @@ private RequestResponse sendRequest(Request request) {
} catch (Exception ex) {
error(ex, null, getParser().getNode());
}

try (var client = new RequestClient((URL != null ? URL : request.uri()).toString().replaceAll("§", "&"))) {
RequestResponse rsp;
if (hasAttachments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.LinkedList;

import static cz.coffee.skjson.utils.Util.fstring;

@Name("Request headers")
Expand Down Expand Up @@ -97,16 +100,15 @@ public void change(@NotNull Event event, Object @NotNull [] delta, Changer.@NotN
var request = getExpr().getSingle(event);
assert request != null;
if (mode == Changer.ChangeMode.SET) {
Pairs[] pairs = new Pairs[delta.length];
for (var i = 0; i < delta.length; i++) {
var d = delta[i];
LinkedList<Pairs> pairs = new LinkedList<>();
for (Object d : delta) {
if (d instanceof String str) {
pairs[i] = new Pairs(str);
pairs.add(new Pairs(str));
} else if (d instanceof JsonElement json) {
pairs[i] = new Pairs(json);
json.getAsJsonObject().entrySet().forEach(entry -> pairs.add(new Pairs(entry.getKey() + ":" +entry.getValue().getAsString())));
}
}
request.setHeader(pairs);
request.setHeader(pairs.toArray(new Pairs[0]));
} else if (mode == Changer.ChangeMode.RESET) {
request.setHeader(new Pairs[0]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: SkJson
version: '${project.version}'
main: cz.coffee.skjson.SkJson
api-version: '1.16'
revision-version: '4552fe8ba'
full-revision-sha1: '4552fe8ba495afac07a1d93cbb777d4ccdd763808b1c9d740696612efe183c79'
revision-version: 'd4eb6e046'
full-revision-sha1: 'd4eb6e046bdf624dcae0b4cb3a3bda785d6b211534aa1d5099ac8c684819d0d5'
depend:
- Skript
prefix: SkJson
Expand Down

0 comments on commit 1d97d4a

Please sign in to comment.