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

Commit

Permalink
Switched to Jackson JSON for Teams sample #52
Browse files Browse the repository at this point in the history
  • Loading branch information
tracyboehrer committed Feb 22, 2021
1 parent b953156 commit 07b1a41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@
<version>4.6.1-preview8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20201115</version>
<scope>compile</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

package com.microsoft.bot.sample.teamssearchauth;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.microsoft.bot.builder.StatePropertyAccessor;
import com.microsoft.bot.builder.TurnContext;
import com.microsoft.bot.builder.UserState;
Expand All @@ -18,8 +21,6 @@
import okhttp3.Response;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;

import java.io.IOException;
Expand Down Expand Up @@ -133,11 +134,14 @@ private CompletableFuture<MessagingExtensionResponse> packageExtensionQuery(
return findPackages(search).thenApply(packages -> {
List<MessagingExtensionAttachment> attachments = new ArrayList<>();
for (String[] item : packages) {
ObjectNode data = Serialization.createObjectNode();
data.set("data", Serialization.objectToTree(item));

ThumbnailCard previewCard = new ThumbnailCard() {{
setTitle(item[0]);
setTap(new CardAction() {{
setType(ActionTypes.INVOKE);
setValue(new JSONObject().put("data", item).toString());
setValue(data);
}});
}};

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

dataArray.forEach(i -> {
JSONObject item = (JSONObject) i;
for (int i = 0; i < dataArray.size(); i++) {
JsonNode item = dataArray.get(i);
filteredItems.add(
new String[]{
item.getString("id"), item.getString("version"),
item.getString("description"),
item.has("projectUrl") ? item.getString("projectUrl") : "",
item.has("iconUrl") ? item.getString("iconUrl") : ""
new String[] {
item.get("id").asText(),
item.get("version").asText(),
item.get("description").asText(),
item.has("projectUrl") ? item.get("projectUrl").asText() : "",
item.has("iconUrl") ? item.get("iconUrl").asText() : ""
}
);
});

}
} catch (IOException e) {
LoggerFactory.getLogger(TeamsMessagingExtensionsSearchAuthConfigBot.class)
.error("findPackages", e);
Expand Down

0 comments on commit 07b1a41

Please sign in to comment.