BAEL-5115 Deduction-Based Polymorphism in Jackson 2.12 (#11732)
* BAEL-5115 Deduction-Based Polymorphism in Jackson 2.12 * Fix pmd * Code review changes * Improvements * Code review * Code review * fix typo * Rename package * Apply formatter * Add old deduction * revert
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.jackson.deductionbasedpolymorphism;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
|
||||
|
||||
@JsonTypeInfo(use = Id.DEDUCTION)
|
||||
@JsonSubTypes({ @Type(ImperialSpy.class), @Type(King.class), @Type(Knight.class) })
|
||||
public interface Character {
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.jackson.deductionbasedpolymorphism;
|
||||
|
||||
public class ControlledCharacter {
|
||||
|
||||
private Character character;
|
||||
|
||||
public Character getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
public void setCharacter(Character character) {
|
||||
this.character = character;
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.jackson.deductionbasedpolymorphism;
|
||||
|
||||
public class ImperialSpy implements Character {
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.jackson.deductionbasedpolymorphism;
|
||||
|
||||
public class King extends NamedCharacter {
|
||||
|
||||
private String land;
|
||||
|
||||
public String getLand() {
|
||||
return land;
|
||||
}
|
||||
|
||||
public void setLand(String land) {
|
||||
this.land = land;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.jackson.deductionbasedpolymorphism;
|
||||
|
||||
public class Knight extends NamedCharacter {
|
||||
|
||||
private String weapon;
|
||||
|
||||
public String getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public void setWeapon(String weapon) {
|
||||
this.weapon = weapon;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.jackson.deductionbasedpolymorphism;
|
||||
|
||||
public class NamedCharacter implements Character {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user