Add JSON properties.
[rhynodge.git] / src / main / java / net / pterodactylus / reactor / states / AbstractState.java
index e35c933..674f4af 100644 (file)
@@ -19,14 +19,22 @@ 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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
+@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. */
        private final boolean success;
 
@@ -71,6 +79,7 @@ public abstract class AbstractState implements State {
         *            The exception that occured while retrieving the state
         */
        protected AbstractState(boolean success, Throwable exception) {
+               this.time = System.currentTimeMillis();
                this.success = success;
                this.exception = exception;
        }
@@ -83,6 +92,14 @@ public abstract class AbstractState implements State {
         * {@inheritDoc}
         */
        @Override
+       public long time() {
+               return time;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
        public boolean success() {
                return success;
        }