Created
May 12, 2020 06:48
-
-
Save abelaska/e814cf9f79baef438283a9d760e68873 to your computer and use it in GitHub Desktop.
Java Jackson @JsonSubTypes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.annotation.JsonSubTypes; | |
import com.fasterxml.jackson.annotation.JsonTypeInfo; | |
import lombok.Data; | |
import java.util.HashMap; | |
import java.util.Map; | |
@Data | |
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "kind", visible = true) | |
@JsonSubTypes({ | |
@JsonSubTypes.Type(value = OAuth2Application.class, name = "OAuth2Application"), | |
@JsonSubTypes.Type(value = PropertyMap.class, name = "PropertyMap") | |
}) | |
public abstract class Kind { | |
String apiVersion; | |
String kind; | |
Map<String, String> metadata = new HashMap<>(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Data; | |
import lombok.ToString; | |
@Data | |
@ToString(callSuper = true) | |
public class OAuth2Application extends Kind { | |
Spec spec; | |
@Data | |
public class Spec { | |
String name; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Data; | |
import lombok.ToString; | |
import java.util.Map; | |
@Data | |
@ToString(callSuper = true) | |
public class PropertyMap extends Kind { | |
Map<String, String> data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment