Skip to content

Commit cad6129

Browse files
Indentation fix and eventId checking. Invitable deserializer now throws exception if it cannot parse JSON into an Invitee or Invitation.
1 parent 2644901 commit cad6129

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

src/main/java/com/robinpowered/sdk/model/adapter/InvitableAdapter.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,30 @@
1313
import java.lang.reflect.Type;
1414

1515
/**
16-
* Handles adapting {@link Invitable} from string representations.
16+
* Handles adapting {@link Invitable} from JSON representations.
1717
*/
1818
public class InvitableAdapter implements JsonDeserializer<Invitable>, JsonSerializer<Invitable> {
1919

20-
/**
21-
* Build an InvitableAdapter
22-
*/
23-
public InvitableAdapter() {
24-
}
25-
2620
@Override
2721
public Invitable deserialize(
28-
JsonElement json,
29-
Type typeOfT,
30-
JsonDeserializationContext context
22+
JsonElement json,
23+
Type typeOfT,
24+
JsonDeserializationContext context
3125
) throws JsonParseException {
3226

33-
JsonObject object = json.getAsJsonObject();
34-
boolean isInvitation = object.has("email") && !object.has("id");
35-
boolean isInivtee = object.has("email")
36-
&& object.has("id");
27+
JsonObject object = json.getAsJsonObject();
28+
boolean isInvitation = object.has("email") && !object.has("id");
29+
boolean isInvitee = object.has("email")
30+
&& object.has("id")
31+
&& object.has("eventId");
3732

38-
if (isInvitation) {
39-
return context.deserialize(object, Invitee.Invitation.class);
40-
} else if (isInivtee) {
41-
return context.deserialize(object, Invitee.class);
42-
}
33+
if (isInvitation) {
34+
return context.deserialize(object, Invitee.Invitation.class);
35+
} else if (isInvitee) {
36+
return context.deserialize(object, Invitee.class);
37+
}
4338

44-
return null;
39+
throw new JsonParseException("Malformed json for invitees.");
4540
}
4641

4742
@Override

0 commit comments

Comments
 (0)