Java Jacskon忽略层次结构嵌套类中的@JsonIgnore注释
我目前正在开发一个基于spring的java应用程序 长话短说——下面是我用来从数据库中检索对象、对其进行一些计算并渲染它的代码Java Jacskon忽略层次结构嵌套类中的@JsonIgnore注释,java,json,spring,jackson,Java,Json,Spring,Jackson,我目前正在开发一个基于spring的java应用程序 长话短说——下面是我用来从数据库中检索对象、对其进行一些计算并渲染它的代码 @RequestMapping(value = { "/mapping" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public Object getMasterAppMappingById( @PathVariable(value = "ma
@RequestMapping(value = { "/mapping" }, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Object getMasterAppMappingById(
@PathVariable(value = "masterAppId") Integer masterAppId) {
RestBaseVO masterAppMappingRestBaseVO = new RestBaseVO();
MasterAppMappingTreeDetailsVO masterAppMappingTreeDetailsById = applicationDeviceServices.getMasterAppMappingTreeDetails(masterAppId, true);
return masterAppMappingTreeDetailsById;
}
我的问题是,在jackson加入并转换代码之前,代码一直都很好。
返回语句是我的瓶颈
getMasterAppMappingTreeDetails方法工作完美,性能良好
jackson呈现的json显示在pastebin上的以下url中
正如你所看到的,它相当大
被序列化的类如下所示
public class MasterAppMappingTreeDetailsVO {
@JsonProperty("id")
private Integer id;
@JsonProperty("mappingId")
private Integer mappingId;
@JsonProperty("parentMappingId")
private Integer parentMappingId;
@JsonProperty("isQuestion")
private boolean isQuestion;
@JsonProperty("isAnswer")
private boolean isAnswer;
@JsonProperty("isApplication")
private boolean isApplication;
@JsonProperty("displayLabel")
private String displayLabel;
@JsonProperty("additionalText1")
private String additionalText1;
@JsonProperty("imageUrl")
private String imageUrl;
@JsonProperty("imageDateUpdated")
private Long imageDateUpdated;
@JsonProperty("appId")
private Integer appId;
@JsonProperty("appName")
private String appName;
@JsonProperty("children")
private List<MasterAppMappingTreeDetailsVO> children;
@JsonProperty("menuStyle")
private MenuStyleVO menuStyle;
}
@Entity
@Table(name = "menu_style")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class MenuStyleVO extends BaseDAOVO implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3697798179195096156L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@Column(name = "menuStyleName", unique = false, nullable = false, length = 200)
private String menuStyleName;
@Column(name = "menuTemplate", unique = false, nullable = false, length = 200)
private String menuTemplate;
@OneToOne(fetch = FetchType.EAGER)
@Cascade({ CascadeType.SAVE_UPDATE })
@JoinColumn(name="logo_id")
@JsonProperty("logo")
private ApplicationImageVO logo;
@Column(name = "logoAlignment", unique = false, nullable = true, length = 20)
private String logoAlignment;
@Column(name = "backArrowColor", unique = false, nullable = true, length = 7)
private String backArrowColor;
@OneToOne(fetch = FetchType.EAGER)
@Cascade({ CascadeType.SAVE_UPDATE })
@JoinColumn(name="backArrowIcon_id")
@JsonProperty("backArrowIcon")
private ApplicationImageVO backArrowIcon;
@Column(name = "questionLabelTextColor", unique = false, nullable = true, length = 7)
private String questionLabelTextColor;
@Column(name = "headerBackgroundColor", unique = false, nullable = true, length = 7)
private String headerBackgroundColor;
@Column(name = "headerBackgroundOpacity", unique = false, nullable = true)
private Integer headerBackgroundOpacity;
@Column(name = "mainBackgroundColor", unique = false, nullable = true, length = 7)
private String mainBackgroundColor;
@Column(name = "mainBackgroundOpacity", unique = false, nullable = true)
private Integer mainBackgroundOpacity;
@OneToOne(fetch = FetchType.EAGER)
@Cascade({ CascadeType.SAVE_UPDATE })
@JoinColumn(name="backgroundImageLandscape_id")
@JsonProperty("backgroundImageLandscape")
private ApplicationImageVO backgroundImageLandscape;
@OneToOne(fetch = FetchType.EAGER)
@Cascade({ CascadeType.SAVE_UPDATE })
@JoinColumn(name="backgroundImagePortrait_id")
@JsonProperty("backgroundImagePortrait")
private ApplicationImageVO backgroundImagePortrait;
@Column(name = "containerColor", unique = false, nullable = true, length = 7)
private String containerColor;
@Column(name = "containerOpacity", unique = false, nullable = true)
private Integer containerOpacity;
@Column(name = "containerLineDividerColor", unique = false, nullable = true, length = 7)
private String containerLineDividerColor;
@Column(name = "containerLineDividerOpacity", unique = false, nullable = true)
private Integer containerLineDividerOpacity;
@Column(name = "optionIconSize", unique = false, nullable = true)
private Integer optionIconSize;
@Column(name = "optionLabelTextColor", unique = false, nullable = true, length = 7)
private String optionLabelTextColor;
@Column(name = "optionTaglinePosition", unique = false, nullable = true, length = 20)
private String optionTaglinePosition;
@Column(name = "optionTaglineTextColor", unique = false, nullable = true, length = 7)
private String optionTaglineTextColor;
@Column(name = "optionSelectionArrowColor", unique = false, nullable = true, length = 7)
private String optionSelectionArrowColor;
@OneToOne(fetch = FetchType.EAGER)
@Cascade({ CascadeType.SAVE_UPDATE })
@JoinColumn(name="optionSelectionArrowIcon_id")
@JsonProperty("optionSelectionArrowIcon")
private ApplicationImageVO optionSelectionArrowIcon;
}
公共类MasterAppMappingTreeDetailsVO{
@JsonProperty(“id”)
私有整数id;
@JsonProperty(“mappingId”)
私有整数映射ID;
@JsonProperty(“parentMappingId”)
私有整数parentMappingId;
@JsonProperty(“isQuestion”)
私人问题;
@JsonProperty(“isAnswer”)
私有布尔isAnswer;
@JsonProperty(“isApplication”)
私有布尔运算的应用;
@JsonProperty(“显示标签”)
私有字符串显示标签;
@JsonProperty(“附加文本1”)
私有字符串additionalText1;
@JsonProperty(“imageUrl”)
私有字符串imageUrl;
@JsonProperty(“ImageDateUpdate”)
私人长图像更新;
@JsonProperty(“appId”)
私有整数appId;
@JsonProperty(“appName”)
私有字符串appName;
@JsonProperty(“儿童”)
私人名单儿童;
@JsonProperty(“menuStyle”)
私有MenuStyleVO menuStyle;
}
@实体
@表(name=“菜单样式”)
@JsonIgnoreProperties({“HibernateLazInitializer”,“handler”})
公共类MenuStyleVO扩展BaseDAOVO实现可序列化{
/**
*
*/
私有静态最终长serialVersionUID=3697798179195096156L;
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
@列(name=“id”,unique=true,nullable=false)
私有整数id;
@列(name=“menuStyleName”,unique=false,nullable=false,length=200)
私有字符串menuStyleName;
@列(name=“menuTemplate”,unique=false,nullable=false,length=200)
私有字符串菜单模板;
@OneToOne(fetch=FetchType.EAGER)
@级联({CascadeType.SAVE_UPDATE})
@JoinColumn(name=“logo\u id”)
@JsonProperty(“徽标”)
私人应用程序图像标志;
@列(name=“logoAlignment”,unique=false,nullable=true,length=20)
私有字符串对齐;
@列(name=“backArrowColor”,unique=false,nullable=true,length=7)
私有字符串背景色;
@OneToOne(fetch=FetchType.EAGER)
@级联({CascadeType.SAVE_UPDATE})
@JoinColumn(name=“backArrowIcon\u id”)
@JsonProperty(“backArrowIcon”)
私有应用程序图像背面箭头图标;
@列(name=“questionLabelTextColor”,unique=false,nullable=true,length=7)
私有字符串questionLabelTextColor;
@列(name=“headerBackgroundColor”,unique=false,nullable=true,length=7)
私有字符串标题backgroundcolor;
@列(name=“headerBackgroundOpacity”,unique=false,nullable=true)
私有整数headerBackgroundOpacity;
@列(name=“mainBackgroundColor”,unique=false,nullable=true,length=7)
私有字符串主背景色;
@列(name=“mainBackgroundOpacity”,unique=false,nullable=true)
私有整数背景不透明度;
@OneToOne(fetch=FetchType.EAGER)
@级联({CascadeType.SAVE_UPDATE})
@JoinColumn(name=“BackgroundImageLandscapture\u id”)
@JsonProperty(“背景图像景观”)
私有应用程序magevo背景图像景观;
@OneToOne(fetch=FetchType.EAGER)
@级联({CascadeType.SAVE_UPDATE})
@JoinColumn(name=“backgroundImagePortrait\u id”)
@JsonProperty(“背景图像肖像”)
私有应用程序ImageVo backgroundImagePortrait;
@列(name=“containerColor”,unique=false,nullable=true,length=7)
私有字符串容器颜色;
@列(name=“containerCapacity”,unique=false,nullable=true)
私有整数容器容量;
@列(name=“containerLineDividerColor”,unique=false,nullable=true,length=7)
私有字符串containerLineDividerColor;
@列(name=“containerLineDividerOpacity”,unique=false,nullable=true)
私有整型容器线性分割能力;
@列(name=“optionize”,unique=false,nullable=true)
私有整数选项大小;
@列(name=“optionLabelTextColor”,unique=false,nullable=true,length=7)
私有字符串选项LabelTextColor;
@列(name=“optionTaglinePosition”,unique=false,nullable=true,length=20)
私有字符串optionTaglinePosition;
@列(name=“optiontaginetextcolor”,unique=false,nullable=true,length=7)
私有字符串optionTaglineTextColor;
@列(name=“optionSelectionRowColor”,unique=false,nullable=true,length=7)
私有字符串选项SelectionRowColor;
@OneToOne(fetch=FetchType.EAGER)
@级联({CascadeType.SAVE_UPDATE})
@JoinColumn(name=“optionSelectionRowIcon\u id”)
@JsonProperty(“选项SelectionRowIcon”)
专用应用程序图像VO选项选择行图标;
}
有人能就如何提高此json调用的性能或如何提高我的应用程序的jackson性能提供建议吗?jackson的问题 如果您正在使用Jackson API序列化实体类,那么放置@JsonIgnore注释可能只满足一种情况,而不是所有情况。
如果您有一些延迟加载的属性,那么一旦Jackson序列化对象,这些属性就会被加载,或者您必须急切地加载它们,这肯定会对性能产生不利影响。
如果您的类之间存在关系(一个多;多个多等),那么Jackson将加载所有类