In my JSON file I have defined customMetrics as
"customMetricHeadings": [
{
"headingName": "CUSTOM VIEWABILITY",
"customMetricCategory": "CUSTOM_VIEWABILITY"
},
{
"headingName": "CUSTOM VIEWABILITY QI",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
}
]
I have defined this customMetricCategory for different metrics in the same JSON file as
{
"columnName": "nonQualifiedForViewabilityAds4",
"columnLabel": "Not viewable ads, Excl. Geo, ?????",
"cellType": "COUNT",
"columnWidth": "CHAR_17",
"cellAggType": "SUM",
"cellAggColumn": "",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
},
{
"columnName": "nonQualifiedForViewabilityPct4",
"columnLabel": "% Non quality: not viewable, Excl. Geo, ?????",
"cellType": "TWO_PRECISION_PERCENT",
"columnWidth": "CHAR_17",
"cellAggType": "WEIGHTED_AVERAGE",
"cellAggColumn": "nonQualifiedAds4",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
},
{
"columnName": "nonQualifiedForBrandSafetyAds4",
"columnLabel": "Failed brand safety ads, Excl. Geo, ?????",
"cellType": "COUNT",
"columnWidth": "CHAR_17",
"cellAggType": "SUM",
"cellAggColumn": "",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
},
{
"columnName": "nonQualifiedForBrandSafetyPct4",
"columnLabel": "% Non quality: failed brand safety, Excl. Geo, ?????",
"cellType": "TWO_PRECISION_PERCENT",
"columnWidth": "CHAR_17",
"cellAggType": "WEIGHTED_AVERAGE",
"cellAggColumn": "nonQualifiedAds4",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
},
{
"columnName": "nonQualifiedForFraudAds4",
"columnLabel": "Invalid traffic ads, Excl. Geo, ?????",
"cellType": "COUNT",
"columnWidth": "CHAR_17",
"cellAggType": "SUM",
"cellAggColumn": "",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
},
{
"columnName": "nonQualifiedForFraudPct4",
"columnLabel": "% Non quality: IVT, Excl. Geo, ?????",
"cellType": "TWO_PRECISION_PERCENT",
"columnWidth": "CHAR_17",
"cellAggType": "WEIGHTED_AVERAGE",
"cellAggColumn": "nonQualifiedAds4",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
},
{
"columnName": "nonQualifiedForGeoAds4",
"columnLabel": "Out of geo ads, Excl. Geo, ?????",
"cellType": "COUNT",
"columnWidth": "CHAR_17",
"cellAggType": "SUM",
"cellAggColumn": "",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
},
{
"columnName": "nonQualifiedForGeoPct4",
"columnLabel": "% Non quality: Out of geo, Excl. Geo, ?????",
"cellType": "TWO_PRECISION_PERCENT",
"columnWidth": "CHAR_17",
"cellAggType": "WEIGHTED_AVERAGE",
"cellAggColumn": "nonQualifiedAds4",
"customMetricCategory": "CUSTOM_VIEWABILITY_QI"
}
While running the repo in my local, build is failing with the following error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CRBTemplates': Invocation of init method failed; nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "customMetricCategory" (class com.integralads.crbworker.output.template.json.TemplateColumn), not marked as ignorable (6 known properties: "columnWidth", "columnName", "cellAggColumn", "cellAggType", "cellType", "columnLabel"])
at [Source: (URL); line: 2170, column: 32] (through reference chain: com.integralads.crbworker.output.template.json.Template["columns"]->java.util.ArrayList[205]->com.integralads.crbworker.output.template.json.TemplateColumn["customMetricCategory"])
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593)
... 98 common frames omitted
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "customMetricCategory" (class com.integralads.crbworker.output.template.json.TemplateColumn), not marked as ignorable (6 known properties: "columnWidth", "columnName", "cellAggColumn", "cellAggType", "cellType", "columnLabel"])
Do I need to define anything else for this customMetricCategory? How can I get rid of this error?
TemplateColumn.java class
package com.integralads.crbworker.output.template.json;
import com.integralads.crbworker.excel.core.ReportCell;
import com.integralads.crbworker.excel.core.ReportColumnWidth;
public class TemplateColumn {
private String columnName;
private String columnLabel;
private ReportCell.CellType cellType;
private ReportColumnWidth columnWidth;
private ReportCell.CellAggType cellAggType;
private String cellAggColumn;
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public String getColumnLabel() {
return columnLabel;
}
public void setColumnLabel(String columnLabel) {
this.columnLabel = columnLabel;
}
public ReportCell.CellType getCellType() {
return cellType;
}
public void setCellType(ReportCell.CellType cellType) {
this.cellType = cellType;
}
public ReportColumnWidth getColumnWidth() {
return columnWidth;
}
public void setColumnWidth(ReportColumnWidth columnWidth) {
this.columnWidth = columnWidth;
}
public ReportCell.CellAggType getCellAggType() {
return cellAggType;
}
public void setCellAggType(ReportCell.CellAggType cellAggType) {
this.cellAggType = cellAggType;
}
public String getCellAggColumn() {
return cellAggColumn;
}
public void setCellAggColumn(String cellAggColumn) {
this.cellAggColumn = cellAggColumn;
}
}
Also there is a TemplateCustomMetricheading.java class also define for the customMetricCategory
package com.integralads.crbworker.output.template.json;
public class TemplateCustomMetricHeading {
private String headingName;
private CustomMetricCategory customMetricCategory;
public String getHeadingName() {
return headingName;
}
public void setHeadingName(String headingName) {
this.headingName = headingName;
}
public CustomMetricCategory getCustomMetricCategory() {
return customMetricCategory;
}
public void setCustomMetricCategory(CustomMetricCategory customMetricCategory) {
this.customMetricCategory = customMetricCategory;
}
}
CodePudding user response:
There are two ways to get rid of the error:
- Add the missing field
private CustomMetricCategory customMetricCategory
to theTemplateColumn
class and implement related getter/setter to comply with the input JSON:
public class TemplateColumn {
private String columnName;
private String columnLabel;
private ReportCell.CellType cellType;
private ReportColumnWidth columnWidth;
private ReportCell.CellAggType cellAggType;
private String cellAggColumn;
private CustomMetricCategory customMetricCategory;
// ... getters/setters
}
- Ignore failing on unknown properties when deserializing instances of
TemplateColumn
class.
@JsonIgnoreProperties(ignoreUnknown = true)
public class TemplateColumn {
...
}