'jackson deserialize object from id array
i have this targetGroup.json
{
"$schema": "./targetGroup.schema.json",
"targetGroupId": "grp01",
"targetGroupDescription": "default grp",
"outputHandlers": ["1","2"],
}
and outputHandler.json
[
{
"$schema": "./outputHandler.schema.json",
"outputHandlerId": "1",
"outputHandlerName": "com.output.DefaultHtmlOutputPlugin"
},
{
"$schema": "./outputHandler.schema.json",
"outputHandlerId": "2",
"outputHandlerName": "com.output.DefaultCsvOutputPlugin"
}
]
TargetGroup.java
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "targetGroupId")
public class TargetGroup {
private String targetGroupId;
private String targetGroupDescription;
@JsonIdentityReference(alwaysAsId = true)
private List<OutputHandler> outputHandlers;
public String getTargetGroupId() {
return targetGroupId;
}
public void setTargetGroupId(String targetGroupId) {
this.targetGroupId = targetGroupId;
}
public String getTargetGroupDescription() {
return targetGroupDescription;
}
public void setTargetGroupDescription(String targetGroupDescription) {
this.targetGroupDescription = targetGroupDescription;
}
public List<OutputHandler> getOutputHandlers() {
return outputHandlers;
}
public void setOutputHandlers(List<OutputHandler> outputHandlers) {
this.outputHandlers = outputHandlers;
}
}
and OutputHandler.java
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "outputHandlerId")
public class OutputHandler {
@JsonFormat(shape = JsonFormat.Shape.STRING)
private long outputHandlerId;
private String outputHandlerName;
public long getOutputHandlerId() {
return outputHandlerId;
}
public void setOutputHandlerId(long outputHandlerId) {
this.outputHandlerId = outputHandlerId;
}
public String getOutputHandlerName() {
return outputHandlerName;
}
public void setOutputHandlerName(String outputHandlerName) {
this.outputHandlerName = outputHandlerName;
}
}
I'm trying to create the outputHandler objects from the array ["1","2"] which contains onls the IDs of the outputHandlers. Below is the current output when i set mapper.disable(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS). Ist it possible to create outputHandlers from the id array ["1","2"] in TargetGroup?
{
"targetGroupId" : "grp01",
"targetGroupDescription" : "default grp",
"outputHandlers" : [ ]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|