Custom JsonSerializer and polymorphism

Apologies if this has been asked before (it probably has been, but I'm failing at coming up with proper search queries apparently).

This question is about writing custom JsonSerializer classes using Jackson (Java).

I am currently trying to write custom JsonSerializer classes for a simple class hierarchy that looks like this (example):

Pet class:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "petType")

@JsonSubTypes({

@JsonSubTypes.Type(value = Cat.class, name = "cat"),

@JsonSubTypes.Type(value = Dog.class, name = "dog")

})

public abstract class Pet {

// Attributes...

}

Dog class:

public class Dog extends Pet {

// Additional attributes...

}

Cat class:

public class Cat extends Pet...

Read More »

By: StackOverFlow - Saturday, 14 April

Related Posts