From 7cc0345d0ed05aba95c7ede138685195cc7e95cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 6 Jan 2013 11:54:56 +0100 Subject: [PATCH] Add JSON properties. --- .../pterodactylus/reactor/states/AbstractState.java | 5 +++++ .../pterodactylus/reactor/states/TorrentState.java | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/reactor/states/AbstractState.java b/src/main/java/net/pterodactylus/reactor/states/AbstractState.java index f8d6f69..674f4af 100644 --- a/src/main/java/net/pterodactylus/reactor/states/AbstractState.java +++ b/src/main/java/net/pterodactylus/reactor/states/AbstractState.java @@ -19,15 +19,20 @@ package net.pterodactylus.reactor.states; import net.pterodactylus.reactor.State; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + /** * Abstract implementation of a {@link State} that knows about the basic * attributes of a {@link State}. * * @author David ‘Bombe’ Roden */ +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") public abstract class AbstractState implements State { /** The time of this state. */ + @JsonProperty private final long time; /** Whether the state was successfully retrieved. */ diff --git a/src/main/java/net/pterodactylus/reactor/states/TorrentState.java b/src/main/java/net/pterodactylus/reactor/states/TorrentState.java index 9e9659d..f3b3546 100644 --- a/src/main/java/net/pterodactylus/reactor/states/TorrentState.java +++ b/src/main/java/net/pterodactylus/reactor/states/TorrentState.java @@ -27,6 +27,7 @@ import net.pterodactylus.reactor.states.TorrentState.TorrentFile; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.Lists; /** @@ -38,7 +39,8 @@ import com.google.common.collect.Lists; public class TorrentState extends AbstractState implements Iterable { /** The torrent files. */ - private final List files = Lists.newArrayList(); + @JsonProperty + private List files = Lists.newArrayList(); // // ACCESSORS @@ -88,27 +90,42 @@ public class TorrentState extends AbstractState implements Iterable public static class TorrentFile { /** The name of the file. */ + @JsonProperty private final String name; /** The size of the file. */ + @JsonProperty private final String size; /** The magnet URI of the file. */ + @JsonProperty private final String magnetUri; /** The download URI of the file. */ + @JsonProperty private final String downloadUri; /** The number of files in this torrent. */ + @JsonProperty private final int fileCount; /** The number of seeds connected to this torrent. */ + @JsonProperty private final int seedCount; /** The number of leechers connected to this torrent. */ + @JsonProperty private final int leechCount; /** + * No-arg constructor for deserialization. + */ + @SuppressWarnings("unused") + private TorrentFile() { + this(null, null, null, null, 0, 0, 0); + } + + /** * Creates a new torrent file. * * @param name -- 2.7.4