Give Cookie a toJson method
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Map;
+import java.util.TreeMap;
public class Cookie implements Serializable {
private static final long serialVersionUID = 4115876353625612383L;
@@ -176,6 +178,35 @@ public void validate() {
}
}
+ public Map<String, Object> toJson() {
+ Map<String, Object> toReturn = new TreeMap<>();
+
+ if (getDomain() != null) {
+ toReturn.put("domain", getDomain());
+ }
+
+ if (getExpiry() != null) {
+ toReturn.put("expiry", getExpiry());
+ }
+
+ if (getName() != null) {
+ toReturn.put("name", getName());
+ }
+
+ if (getPath() != null) {
+ toReturn.put("path", getPath());
+ }
+
+ if (getValue() != null) {
+ toReturn.put("value", getValue());
+ }
+
+ toReturn.put("secure", isSecure());
+ toReturn.put("httpOnly", isHttpOnly());
+
+ return toReturn;
+ }
+
@Override
public String toString() {
return name + "=" + value
