Created
July 19, 2023 08:28
-
-
Save xstefank/b482836adeb2631108074869ecbcea0a to your computer and use it in GitHub Desktop.
This file contains 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
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS com.fasterxml.jackson.core:jackson-databind:2.15.2 | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import java.util.List; | |
class Task { | |
public String name; | |
} | |
class TimedTask extends Task { | |
public int duration; | |
} | |
class Employee { | |
public int id; | |
public List<Task> tasks; | |
} | |
class Manager extends Employee { | |
public List<TimedTask> tasks; | |
} | |
public class jacksonInheritence { | |
public static void main(String... args) throws Exception { | |
String managerString = "{ \"id\": 1, \"tasks\": [ { \"duration\": 7 } ]}"; | |
ObjectMapper mapper = new ObjectMapper(); | |
Manager manager = mapper.readValue(managerString, Manager.class); | |
System.out.println(manager.id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment