FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.53k stars 1.38k forks source link

Polymorphic serialization: Multiple Property to define Sub Class #2957

Open spremthi57 opened 3 years ago

spremthi57 commented 3 years ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Currently JsonTypeInfo property accepts only String, meaning only one property we can pass to define Subclaseses. I am not able to Deserialize if my subclasses depends on two or more properties

Describe the solution you'd like A clear and concise description of what you want to happen JsonTypeInfo property accepts String Array and all the properties associated should be of type String. And properties associated should be of default as empty string

Usage example If you have a clear idea of how to use proposed new/modified feature, please show an example.

public abstract class Animal {
     private String type;
     private String breed;
}

public class Dog extends Animal {
      private String dogCharacters;
}

public class Bulldog extends Dog {
       private boolean lessNoisy;
}

public class Cat extends Animal {
       private String catCharacters;
}

In this Dog and Cat, depends on type and Bulldog depends on type and breed

cowtowncoder commented 3 years ago

Right, there is no support for multi-property (combo) type ids, and no plans to add any.

lpandzic commented 4 months ago

If you don't mind using external modules - this might help you https://github.com/infobip/infobip-jackson-extension?tab=readme-ov-file#MultiLevelHierarchies - multi level hierarchies based on multiple properties.