我正在尝试将以下对象转换为 JSON:
public class Product {
private ProductEntity productEntity;
private Priority priority;
public Product() {
}
public Product(ProductEntity productEntity, Priority priority) {
this.productEntity = productEntity;
this.priority = priority;
}
public ProductEntity getProductEntity() {
return productEntity;
}
private void setProductEntity(ProductEntity productEntity) {
this.productEntity = productEntity;
}
@JsonView({Views.ShutdownView.class})
public Priority getPriority() {
return priority;
}
使用此代码:
logger.info("Booting up: "+this);
mapper.getSerializationConfig().withView(Views.ShutdownView.class);
//recover previously saved queue if needed
if (getEntity().getQueue() != null && getEntity().getQueue().length > 0) {
try {
queue = mapper.readValue(getEntity().getQueue(), new TypeReference<ArrayList<JobSet>>() {});
//now that it's read correctly, erase the saved data
getEntity().setQueue(null);
workflowProcessService.save(getEntity());
} catch (IOException e) {
e.printStackTrace();
logger.info("Unable to parse JSON");
}
}
出于某种原因, 的输出getProductEntity()
继续显示在 JSON 中。由于我使用的是视图并且没有注释,我希望它不会出现在这里。我是在错误地使用视图还是在我缺少的地方有其他配置?