类继承父类遇到和父类同名不同类型的属性可以用json注解转化@JsonProperty

子类继承父类遇到和父类同名不同类型的属性可以用json注解转化@JsonProperty,继承主要为了抽象公用方法,
有时子类的有字段拓展,A1 extend A,  c1 extend c  a1包含c a包含 c1 此时c1,c不可同名
在实体转化成json的时候,同名的子类覆盖父类属性值

 

package com.mcd.cn.rdc.pcm.product.business.vo.product;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mcd.cn.rdc.pcm.product.business.vo.menu.MenuComboCompositionlForNewVo;
import com.mcd.cn.rdc.pcm.product.business.vo.menu.MenuForNewVO;
import com.mcd.cn.rdc.pcm.product.business.vo.menu.ProductGroupForNewVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * @author: yuhui
 */
@Data
@ApiModel(description = "缓存商品信息")
@Accessors(chain = true)
public class ProductDetailVO extends MenuForNewVO {

    @ApiModelProperty(value = "商品中文长名称", required = true, notes = "如:麦麦脆汁鸡2块(含:1块鸡胸 + 1块鸡腿)", position = 13,allowableValues = "1,2")
    private String productLongNameCn;
    @ApiModelProperty(value = "商品英文长名称", required = true, notes = "如:麦麦脆汁鸡2块(含:1块鸡胸 + 1块鸡腿)", position = 13,allowableValues = "1,2")
    private String productLongNameEn;
    @ApiModelProperty(value = "商品中文描述", required = true, position = 13,allowableValues = "1,2")
    private String descCn;
    @ApiModelProperty(value = "商品英文描述", required = true, position = 13,allowableValues = "1,2")
    private String descEn;
    @ApiModelProperty(value = "套餐组对象", required = true, notes = "如果单品中存在特制属性,也需要在产品组对象中有值", example = "", position = 14)
    @JsonProperty("comboComprisesList")
    private List comboComprisesDetailList;
    private List grillList;
    @ApiModelProperty(value = "商品组对象", required = true, notes = "存商品组子项", example = "", position = 14)
    private List specsList;
    @ApiModelProperty(value = "商品组对象", required = true, notes = "存商品组子项", example = "", position = 14)
    @JsonProperty("productGroupList")
    private List productGroupDetailList;
    /**
     *是否存在特制,example:1:有特制 0:无特制
     */
    private Integer hasGrill;


    @JsonIgnore
    private String daypart;
//    @JsonIgnore
//    private String salesPeriod;
//    @JsonIgnore
//    private String salesTime;
}

 

 

 

package com.mcd.cn.rdc.pcm.product.business.vo.menu;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mcd.cn.rdc.pcm.product.business.vo.product.ProductSalesDaypartVO;
import com.mcd.cn.rdc.pcm.product.business.vo.product.ProductSalesPeriodVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * @author: yuhui
 */
@Data
@ApiModel(description = "菜单信息根据类别")
@Accessors(chain = true)
public class MenuForNewVO {

    @ApiModelProperty(value = "商品id", required = true, example = "", position = 0)
    private Long id;
    @ApiModelProperty(value = "商品编码", required = true, example = "", position = 0)
    private String productCode;
    @ApiModelProperty(value = "菜单商品显示名称中文", required = true, notes = "如:麦麦脆汁鸡2块", position = 1)
    private String productNameCn;
    @ApiModelProperty(value = "菜单商品显示名称英文", notes = "如:McCrispy Chicken-2pcs", position = 2)
    private String productNameEn;
    @ApiModelProperty(value = "价格组redis存储key", required = true, notes = "redis存储key", example = "", position = 3)
    private String priceGroupInfo;
    @ApiModelProperty(value = "商品图片相对路径redis存储key", required = true, notes = "只有图片名称,图片路径需要前台配置redis存储key", example = "", position = 4)
    private String productImage;
    @ApiModelProperty(value = "每周售卖日", required = true, notes = "7位数字表示一周中每天的售卖情况, 1:可售; 0:不可售. 例: 1111100, 表示周一到周五可售", example = "", position = 4)
    private String  dayOfWeek;
    @ApiModelProperty(value = "菜品类别", required = true, notes = "1:单品 2:套餐 3:产品组", position = 11,allowableValues = "1,2,3")
    private String productType;
    @ApiModelProperty(value = "售卖标识", required = true, notes = "1:可卖,0:不可买,2:隐藏", position = 12,allowableValues = "0,1,2")
    private String saleFlag;
    @ApiModelProperty(value = "商品组的前端交互方式", required = true, notes = "1:单品到详情页;2:产品组到详情页", position = 13,allowableValues = "1,2")
    private String  uiType;
    @ApiModelProperty(value = "商品组对象", required = true, notes = "存商品组子项", example = "", position = 14)
    private List productGroupList;
    @ApiModelProperty(value = "bu", required = true, notes = "商品bu", position = 13,allowableValues = "1,2")
    private String  bu;
    @ApiModelProperty(value = "套餐组对象", required = true, notes = "如果单品中存在特制属性,也需要在产品组对象中有值", example = "", position = 14)
    private List comboComprisesList;
    private List productTagList;
    @ApiModelProperty(value = "商品售卖期间", required = true, notes = "商品售卖期间", example = "", position = 14)
    private List salesPeriod;
    @ApiModelProperty(value = "售卖时间段", required = true, notes = "商品每天的售卖时间段,与指定的餐段时间取交集为实际有效售卖时间", example = "", position = 14)
    private List salesTime;

    @JsonIgnore
    private String daypart;
//    @JsonIgnore
//    private String salesPeriod;
//    @JsonIgnore
//    private String salesTime;
}

你可能感兴趣的:(类继承父类遇到和父类同名不同类型的属性可以用json注解转化@JsonProperty)