001package com.box.sdkgen.schemas.aiagentallowedentity; 002 003import com.box.sdkgen.internal.OneOfTwo; 004import com.box.sdkgen.schemas.groupbase.GroupBase; 005import com.box.sdkgen.schemas.userbase.UserBase; 006import com.box.sdkgen.serialization.json.EnumWrapper; 007import com.box.sdkgen.serialization.json.JsonManager; 008import com.fasterxml.jackson.core.JsonParser; 009import com.fasterxml.jackson.databind.DeserializationContext; 010import com.fasterxml.jackson.databind.JsonDeserializer; 011import com.fasterxml.jackson.databind.JsonMappingException; 012import com.fasterxml.jackson.databind.JsonNode; 013import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 014import com.fasterxml.jackson.databind.annotation.JsonSerialize; 015import java.io.IOException; 016 017@JsonDeserialize(using = AiAgentAllowedEntity.AiAgentAllowedEntityDeserializer.class) 018@JsonSerialize(using = OneOfTwo.OneOfTwoSerializer.class) 019public class AiAgentAllowedEntity extends OneOfTwo<UserBase, GroupBase> { 020 021 protected final String id; 022 023 protected final String type; 024 025 public AiAgentAllowedEntity(UserBase userBase) { 026 super(userBase, null); 027 this.id = userBase.getId(); 028 this.type = EnumWrapper.convertToString(userBase.getType()); 029 } 030 031 public AiAgentAllowedEntity(GroupBase groupBase) { 032 super(null, groupBase); 033 this.id = groupBase.getId(); 034 this.type = EnumWrapper.convertToString(groupBase.getType()); 035 } 036 037 public boolean isUserBase() { 038 return value0 != null; 039 } 040 041 public UserBase getUserBase() { 042 return value0; 043 } 044 045 public boolean isGroupBase() { 046 return value1 != null; 047 } 048 049 public GroupBase getGroupBase() { 050 return value1; 051 } 052 053 public String getId() { 054 return id; 055 } 056 057 public String getType() { 058 return type; 059 } 060 061 static class AiAgentAllowedEntityDeserializer extends JsonDeserializer<AiAgentAllowedEntity> { 062 063 public AiAgentAllowedEntityDeserializer() { 064 super(); 065 } 066 067 @Override 068 public AiAgentAllowedEntity deserialize(JsonParser jp, DeserializationContext ctxt) 069 throws IOException { 070 JsonNode node = JsonManager.jsonToSerializedData(jp); 071 JsonNode discriminant0 = node.get("type"); 072 if (!(discriminant0 == null)) { 073 switch (discriminant0.asText()) { 074 case "user": 075 return new AiAgentAllowedEntity(JsonManager.deserialize(node, UserBase.class)); 076 case "group": 077 return new AiAgentAllowedEntity(JsonManager.deserialize(node, GroupBase.class)); 078 } 079 } 080 throw new JsonMappingException(jp, "Unable to deserialize AiAgentAllowedEntity"); 081 } 082 } 083}