[grid] Helping json to map properly Slot.java
This was causing an issue that ended up mapping
the id value incorrectly.
Fixes
package org.openqa.selenium.grid.data;
+import static java.util.Collections.unmodifiableMap;
+
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.internal.Require;
import java.io.Serializable;
import java.time.Instant;
+import java.util.Map;
import java.util.Objects;
+import java.util.TreeMap;
public class Slot implements Serializable {
@@ -42,6 +46,51 @@ public Slot(SlotId id, Capabilities stereotype, Instant lastStarted, Session ses
this.slotMatcher = new DefaultSlotMatcher();
}
+ private static Slot fromJson(JsonInput input) {
+ SlotId id = null;
+ Capabilities stereotype = null;
+ Instant lastStarted = null;
+ Session session = null;
+
+ input.beginObject();
+ while (input.hasNext()) {
+ String name = input.nextName();
+ switch (name) {
+ case "id":
+ id = input.read(SlotId.class);
+ break;
+
+ case "lastStarted":
+ lastStarted = input.read(Instant.class);
+ break;
+
+ case "session":
+ session = input.read(Session.class);
+ break;
+
+ case "stereotype":
+ stereotype = input.read(Capabilities.class);
+ break;
+
+ default:
+ input.skipValue();
+ break;
+ }
+ }
+ input.endObject();
+
+ return new Slot(id, stereotype, lastStarted, session);
+ }
+
+ private Map<String, Object> toJson() {
+ Map<String, Object> toReturn = new TreeMap<>();
+ toReturn.put("id", getId());
+ toReturn.put("lastStarted", getLastStarted());
+ toReturn.put("session", getSession());
+ toReturn.put("stereotype", getStereotype());
+ return unmodifiableMap(toReturn);
+ }
+
public SlotId getId() {
return id;
}
@@ -79,40 +128,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(id, stereotype, session, lastStarted.toEpochMilli());
}
-
- private static Slot fromJson(JsonInput input) {
- SlotId id = null;
- Capabilities stereotype = null;
- Instant lastStarted = null;
- Session session = null;
-
- input.beginObject();
- while (input.hasNext()) {
- String name = input.nextName();
- switch (name) {
- case "id":
- id = input.read(SlotId.class);
- break;
-
- case "lastStarted":
- lastStarted = input.read(Instant.class);
- break;
-
- case "session":
- session = input.read(Session.class);
- break;
-
- case "stereotype":
- stereotype = input.read(Capabilities.class);
- break;
-
- default:
- input.skipValue();
- break;
- }
- }
- input.endObject();
-
- return new Slot(id, stereotype, lastStarted, session);
- }
}
