Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit f441624

Browse files
authored
Switched to Jackson JSON for Teams sample #52 (#1014)
1 parent b953156 commit f441624

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

samples/52.teams-messaging-extensions-search-auth-config/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@
8989
<version>4.6.1-preview8</version>
9090
<scope>compile</scope>
9191
</dependency>
92-
<dependency>
93-
<groupId>org.json</groupId>
94-
<artifactId>json</artifactId>
95-
<version>20201115</version>
96-
<scope>compile</scope>
97-
</dependency>
9892
</dependencies>
9993

10094
<profiles>

samples/52.teams-messaging-extensions-search-auth-config/src/main/java/com/microsoft/bot/sample/teamssearchauth/TeamsMessagingExtensionsSearchAuthConfigBot.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
package com.microsoft.bot.sample.teamssearchauth;
55

6+
import com.fasterxml.jackson.databind.JsonNode;
7+
import com.fasterxml.jackson.databind.node.ArrayNode;
8+
import com.fasterxml.jackson.databind.node.ObjectNode;
69
import com.microsoft.bot.builder.StatePropertyAccessor;
710
import com.microsoft.bot.builder.TurnContext;
811
import com.microsoft.bot.builder.UserState;
@@ -18,8 +21,6 @@
1821
import okhttp3.Response;
1922
import org.apache.commons.io.IOUtils;
2023
import org.apache.commons.lang3.StringUtils;
21-
import org.json.JSONArray;
22-
import org.json.JSONObject;
2324
import org.slf4j.LoggerFactory;
2425

2526
import java.io.IOException;
@@ -133,11 +134,14 @@ private CompletableFuture<MessagingExtensionResponse> packageExtensionQuery(
133134
return findPackages(search).thenApply(packages -> {
134135
List<MessagingExtensionAttachment> attachments = new ArrayList<>();
135136
for (String[] item : packages) {
137+
ObjectNode data = Serialization.createObjectNode();
138+
data.set("data", Serialization.objectToTree(item));
139+
136140
ThumbnailCard previewCard = new ThumbnailCard() {{
137141
setTitle(item[0]);
138142
setTap(new CardAction() {{
139143
setType(ActionTypes.INVOKE);
140-
setValue(new JSONObject().put("data", item).toString());
144+
setValue(data);
141145
}});
142146
}};
143147

@@ -348,21 +352,21 @@ private CompletableFuture<List<String[]>> findPackages(String text) {
348352
List<String[]> filteredItems = new ArrayList<String[]>();
349353
try {
350354
Response response = client.newCall(request).execute();
351-
JSONObject obj = new JSONObject(response.body().string());
352-
JSONArray dataArray = (JSONArray) obj.get("data");
355+
JsonNode obj = Serialization.jsonToTree(response.body().string());
356+
ArrayNode dataArray = (ArrayNode) obj.get("data");
353357

354-
dataArray.forEach(i -> {
355-
JSONObject item = (JSONObject) i;
358+
for (int i = 0; i < dataArray.size(); i++) {
359+
JsonNode item = dataArray.get(i);
356360
filteredItems.add(
357-
new String[]{
358-
item.getString("id"), item.getString("version"),
359-
item.getString("description"),
360-
item.has("projectUrl") ? item.getString("projectUrl") : "",
361-
item.has("iconUrl") ? item.getString("iconUrl") : ""
361+
new String[] {
362+
item.get("id").asText(),
363+
item.get("version").asText(),
364+
item.get("description").asText(),
365+
item.has("projectUrl") ? item.get("projectUrl").asText() : "",
366+
item.has("iconUrl") ? item.get("iconUrl").asText() : ""
362367
}
363368
);
364-
});
365-
369+
}
366370
} catch (IOException e) {
367371
LoggerFactory.getLogger(TeamsMessagingExtensionsSearchAuthConfigBot.class)
368372
.error("findPackages", e);

0 commit comments

Comments
 (0)