001package com.box.sdkgen.schemas.appitemassociateditem;
002
003import com.box.sdkgen.internal.OneOfThree;
004import com.box.sdkgen.schemas.filebase.FileBase;
005import com.box.sdkgen.schemas.folderbase.FolderBase;
006import com.box.sdkgen.schemas.weblinkbase.WebLinkBase;
007import com.box.sdkgen.serialization.json.EnumWrapper;
008import com.box.sdkgen.serialization.json.JsonManager;
009import com.fasterxml.jackson.core.JsonParser;
010import com.fasterxml.jackson.databind.DeserializationContext;
011import com.fasterxml.jackson.databind.JsonDeserializer;
012import com.fasterxml.jackson.databind.JsonMappingException;
013import com.fasterxml.jackson.databind.JsonNode;
014import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
015import com.fasterxml.jackson.databind.annotation.JsonSerialize;
016import java.io.IOException;
017
018@JsonDeserialize(using = AppItemAssociatedItem.AppItemAssociatedItemDeserializer.class)
019@JsonSerialize(using = OneOfThree.OneOfThreeSerializer.class)
020public class AppItemAssociatedItem extends OneOfThree<FileBase, FolderBase, WebLinkBase> {
021
022  protected final String id;
023
024  protected final String etag;
025
026  protected final String type;
027
028  public AppItemAssociatedItem(FileBase fileBase) {
029    super(fileBase, null, null);
030    this.id = fileBase.getId();
031    this.etag = fileBase.getEtag();
032    this.type = EnumWrapper.convertToString(fileBase.getType());
033  }
034
035  public AppItemAssociatedItem(FolderBase folderBase) {
036    super(null, folderBase, null);
037    this.id = folderBase.getId();
038    this.etag = folderBase.getEtag();
039    this.type = EnumWrapper.convertToString(folderBase.getType());
040  }
041
042  public AppItemAssociatedItem(WebLinkBase webLinkBase) {
043    super(null, null, webLinkBase);
044    this.id = webLinkBase.getId();
045    this.etag = webLinkBase.getEtag();
046    this.type = EnumWrapper.convertToString(webLinkBase.getType());
047  }
048
049  public boolean isFileBase() {
050    return value0 != null;
051  }
052
053  public FileBase getFileBase() {
054    return value0;
055  }
056
057  public boolean isFolderBase() {
058    return value1 != null;
059  }
060
061  public FolderBase getFolderBase() {
062    return value1;
063  }
064
065  public boolean isWebLinkBase() {
066    return value2 != null;
067  }
068
069  public WebLinkBase getWebLinkBase() {
070    return value2;
071  }
072
073  public String getId() {
074    return id;
075  }
076
077  public String getEtag() {
078    return etag;
079  }
080
081  public String getType() {
082    return type;
083  }
084
085  static class AppItemAssociatedItemDeserializer extends JsonDeserializer<AppItemAssociatedItem> {
086
087    public AppItemAssociatedItemDeserializer() {
088      super();
089    }
090
091    @Override
092    public AppItemAssociatedItem deserialize(JsonParser jp, DeserializationContext ctxt)
093        throws IOException {
094      JsonNode node = JsonManager.jsonToSerializedData(jp);
095      JsonNode discriminant0 = node.get("type");
096      if (!(discriminant0 == null)) {
097        switch (discriminant0.asText()) {
098          case "file":
099            return new AppItemAssociatedItem(JsonManager.deserialize(node, FileBase.class));
100          case "folder":
101            return new AppItemAssociatedItem(JsonManager.deserialize(node, FolderBase.class));
102          case "web_link":
103            return new AppItemAssociatedItem(JsonManager.deserialize(node, WebLinkBase.class));
104        }
105      }
106      throw new JsonMappingException(jp, "Unable to deserialize AppItemAssociatedItem");
107    }
108  }
109}