X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetPostAjaxPage.java;h=51ab3eea55c106fd3e777577005750bc92b656ec;hb=53a71d1d6b91e4d56af49a06f2e06bc4d11bf3eb;hp=8eeedc933fdf3250b1d285539294fe7241710dba;hpb=6e9a43ccd93ae125720547c0fe421dc81a54ba90;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java index 8eeedc9..51ab3ee 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web.ajax; import java.io.StringWriter; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; import com.google.common.base.Optional; @@ -26,11 +27,13 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.io.Closer; -import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.template.TemplateException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + /** * This AJAX handler retrieves information and rendered representation of a * {@link Post}. @@ -59,7 +62,7 @@ public class GetPostAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); Optional post = webInterface.getCore().getPost(postId); if (!post.isPresent()) { @@ -92,8 +95,8 @@ public class GetPostAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the post */ - private JsonObject createJsonPost(FreenetRequest request, Post post, Sone currentSone) { - JsonObject jsonPost = new JsonObject(); + private JsonNode createJsonPost(FreenetRequest request, Post post, Optional currentSone) { + ObjectNode jsonPost = new ObjectNode(instance); jsonPost.put("id", post.getId()); jsonPost.put("sone", post.getSone().getId()); jsonPost.put("recipient", post.getRecipientId().orNull()); @@ -103,7 +106,7 @@ public class GetPostAjaxPage extends JsonPage { templateContext.set("core", webInterface.getCore()); templateContext.set("request", request); templateContext.set("post", post); - templateContext.set("currentSone", currentSone); + templateContext.set("currentSone", currentSone.orNull()); templateContext.set("localSones", webInterface.getCore().getLocalSones()); try { postTemplate.render(templateContext, stringWriter);