Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.josue.shared.online; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes.Type; import com.fasterxml.jackson.annotation.JsonTypeInfo; import java.io.Serializable; /** * @author Josue */ //*** MAPS THE POLYMORPHIC CLASS TO THE PROPERTY 'type' *** @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") //the field name @JsonSubTypes({ @Type(value = NetworkMessage.class, name = "MESSAGE"), @Type(value = NetworkWorld.class, name = "ONLINE"), @Type(value = NetworkConnection.class, name = "CONNECTION"), @Type(value = NetworkPlayer.class, name = "PLAYER") }) public abstract class NetworkPackage implements Serializable { //*** EMPTY CONSTRUCTORS REQUIRED FOR INHERITED CLASSES *** private NetworkMessageType type; public NetworkPackage(NetworkMessageType type) { this.type = type; } public NetworkMessageType getType() { return type; } // public abstract OnlineResource convertFrom(T type); }