|
13 | 13 | import java.lang.reflect.Type; |
14 | 14 |
|
15 | 15 | /** |
16 | | - * Handles adapting {@link Invitable} from string representations. |
| 16 | + * Handles adapting {@link Invitable} from JSON representations. |
17 | 17 | */ |
18 | 18 | public class InvitableAdapter implements JsonDeserializer<Invitable>, JsonSerializer<Invitable> { |
19 | 19 |
|
20 | | - /** |
21 | | - * Build an InvitableAdapter |
22 | | - */ |
23 | | - public InvitableAdapter() { |
24 | | - } |
25 | | - |
26 | 20 | @Override |
27 | 21 | public Invitable deserialize( |
28 | | - JsonElement json, |
29 | | - Type typeOfT, |
30 | | - JsonDeserializationContext context |
| 22 | + JsonElement json, |
| 23 | + Type typeOfT, |
| 24 | + JsonDeserializationContext context |
31 | 25 | ) throws JsonParseException { |
32 | 26 |
|
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"); |
37 | 32 |
|
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 | + } |
43 | 38 |
|
44 | | - return null; |
| 39 | + throw new JsonParseException("Malformed json for invitees."); |
45 | 40 | } |
46 | 41 |
|
47 | 42 | @Override |
|
0 commit comments