I have a Abstact Class say "AbstractChartConfig".
// This is abstract class where I have some common properties of a chart and some methods
@Getter
@Setter
public abstract class AbstractChartConfig {
protected String name;
protected Map<String, Object> type;
protected Map<String, Object> xAxis;
protected Map<String, Object> yAxis;
@JsonIgnore
protected ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
;
protected abstract void setChartType(Map<String, Object> chartType);
public abstract void parseChart(ChartColDto column, HashMap<String, Object> chartData);
}
And a concrete class
@Getter
@Setter
public class PieChart extends AbstractChartConfig {
//Implementing the methods here and setting the properties in abstract class
@Override
public HashMap<String, Object> parseChart(ChartColDto column, HashMap<String, Object> chartData) {
HashMap<String, Object> config = column.getConfig();
setChartType(config.getChartType());
setXAxis(config.getXAxis());
setYAxis(config.getYAxis());
return mapper.convertValue(this, HashMap<String, Object>);
}
@Override
protected void setChartType(Map<String, Object> chartType){
if(null != chartType){
setType(chartType);
}
}
}
And say the config is like
[
{
"config": {
"name": "pie",
"chartType": {
"type": "pie",
"radius": "10"
},
"xAxis": {
"title": "Some Title",
"fontSize": "16px"
},
"yAxis": {
"title": "Some Title",
"fontSize": "16px"
},
"zAxis": {
"title": "Some Title",
"fontSize": "16px"
},
"tooltip": {
"format": "{point.y}"
}
}
}
]
Now, The Problem is when mapper is converting the class to HashMap, the properties which are defined in the abstract class is there in the final result but not the one which is not declared i.e, in this case zAxis, tooltip
Now, I know that in order to deserialize the undeclared properties, if I declare them in concrete class it works fine. But that's what I don't want to do. Is there anyway in which mapper will include the property which is not declared?
Thanks in advance.