001package com.box.sdkgen.schemas.eventsourceresource; 002 003import com.box.sdkgen.internal.OneOfSix; 004import com.box.sdkgen.schemas.appitemeventsource.AppItemEventSource; 005import com.box.sdkgen.schemas.eventsource.EventSource; 006import com.box.sdkgen.schemas.file.File; 007import com.box.sdkgen.schemas.folder.Folder; 008import com.box.sdkgen.schemas.user.User; 009import com.box.sdkgen.serialization.json.JsonManager; 010import com.fasterxml.jackson.core.JsonParser; 011import com.fasterxml.jackson.databind.DeserializationContext; 012import com.fasterxml.jackson.databind.JsonDeserializer; 013import com.fasterxml.jackson.databind.JsonMappingException; 014import com.fasterxml.jackson.databind.JsonNode; 015import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 016import com.fasterxml.jackson.databind.annotation.JsonSerialize; 017import java.io.IOException; 018import java.util.Map; 019 020@JsonDeserialize(using = EventSourceResource.EventSourceResourceDeserializer.class) 021@JsonSerialize(using = OneOfSix.OneOfSixSerializer.class) 022public class EventSourceResource 023 extends OneOfSix<User, EventSource, File, Folder, Map<String, Object>, AppItemEventSource> { 024 025 public EventSourceResource(User user) { 026 super(user, null, null, null, null, null); 027 } 028 029 public EventSourceResource(EventSource eventSource) { 030 super(null, eventSource, null, null, null, null); 031 } 032 033 public EventSourceResource(File file) { 034 super(null, null, file, null, null, null); 035 } 036 037 public EventSourceResource(Folder folder) { 038 super(null, null, null, folder, null, null); 039 } 040 041 public EventSourceResource(Map<String, Object> map) { 042 super(null, null, null, null, map, null); 043 } 044 045 public EventSourceResource(AppItemEventSource appItemEventSource) { 046 super(null, null, null, null, null, appItemEventSource); 047 } 048 049 public boolean isUser() { 050 return value0 != null; 051 } 052 053 public User getUser() { 054 return value0; 055 } 056 057 public boolean isEventSource() { 058 return value1 != null; 059 } 060 061 public EventSource getEventSource() { 062 return value1; 063 } 064 065 public boolean isFile() { 066 return value2 != null; 067 } 068 069 public File getFile() { 070 return value2; 071 } 072 073 public boolean isFolder() { 074 return value3 != null; 075 } 076 077 public Folder getFolder() { 078 return value3; 079 } 080 081 public boolean isMap() { 082 return value4 != null; 083 } 084 085 public Map<String, Object> getMap() { 086 return value4; 087 } 088 089 public boolean isAppItemEventSource() { 090 return value5 != null; 091 } 092 093 public AppItemEventSource getAppItemEventSource() { 094 return value5; 095 } 096 097 static class EventSourceResourceDeserializer extends JsonDeserializer<EventSourceResource> { 098 099 public EventSourceResourceDeserializer() { 100 super(); 101 } 102 103 @Override 104 public EventSourceResource deserialize(JsonParser jp, DeserializationContext ctxt) 105 throws IOException { 106 JsonNode node = JsonManager.jsonToSerializedData(jp); 107 JsonNode discriminant0 = node.get("type"); 108 if (!(discriminant0 == null)) { 109 switch (discriminant0.asText()) { 110 case "user": 111 return new EventSourceResource(JsonManager.deserialize(node, User.class)); 112 case "file": 113 return new EventSourceResource(JsonManager.deserialize(node, File.class)); 114 case "folder": 115 return new EventSourceResource(JsonManager.deserialize(node, Folder.class)); 116 case "app_item": 117 return new EventSourceResource(JsonManager.deserialize(node, AppItemEventSource.class)); 118 } 119 } 120 JsonNode discriminant1 = node.get("item_type"); 121 if (!(discriminant1 == null)) { 122 switch (discriminant1.asText()) { 123 case "file": 124 return new EventSourceResource(JsonManager.deserialize(node, EventSource.class)); 125 case "folder": 126 return new EventSourceResource(JsonManager.deserialize(node, EventSource.class)); 127 } 128 } 129 try { 130 return new EventSourceResource(OneOfSix.OBJECT_MAPPER.convertValue(node, Map.class)); 131 } catch (Exception ignored) { 132 } 133 throw new JsonMappingException(jp, "Unable to deserialize EventSourceResource"); 134 } 135 } 136}