<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      springboot~alibaba.fastjson2序列化時過濾字段

      當我們使用阿里的alibaba.fastjson2進行json序列化時,你可以通過方法參數PropertyFilter來實現對字段的獲取,將需要序列化的字段寫到PropertyFilter對象里,當然也可以將不進行序列化的寫到這里,進行邏輯非操作即可

      實體

      class Person {
          private String firstName;
          private String lastName;
          private int age;
      
          public Person(String firstName, String lastName, int age) {
              this.firstName = firstName;
              this.lastName = lastName;
              this.age = age;
          }
      
          public String getFirstName() {
              return firstName;
          }
      
          public String getLastName() {
              return lastName;
          }
      
      

      過濾掉字段age,可以使用下面的代碼

          public static void main(String[] args) {
              Person person = new Person("John", "Doe", 30);
              PropertyFilter filter = (source, name, value) -> {
                  // 過濾掉名為"age"的屬性
                  return !name.equals("age");
              };
              String json = JSON.toJSONString(person, filter);
              System.out.println(json);
          }
      

      alibaba.fastjson要實現,需要自己寫filter了

      • 定義filter對象,實現ObjectSerializer 接口
      public class ExcludePropertyFilter implements ObjectSerializer {
      
          private final String[] excludeProperties;
      
          public ExcludePropertyFilter(String... excludeProperties) {
              this.excludeProperties = excludeProperties;
          }
      
          @Override
          public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) {
              if (object == null) {
                  serializer.getWriter().writeNull(SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty);
                  return;
              }
              SerializeWriter out = serializer.getWriter();
              out.write('{');
              serializer.incrementIndent();
              boolean skipComma = true; // 標記是否需要跳過逗號
              FieldInfo[] fields = serializer
                  .getFieldSerializerMap()
                  .get(object.getClass())
                  .getFieldInfos();
              for (FieldInfo fieldInfo : fields) {
                  String propertyName = fieldInfo.getName();
                  boolean exclude = false;
                  for (String excludeProperty : excludeProperties) {
                      if (propertyName.equals(excludeProperty)) {
                          exclude = true;
                          break;
                      }
                  }
                  if (exclude) {
                      continue; // 跳過需要排除的屬性
                  }
                  if (!skipComma) {
                      out.write(',');
                  } else {
                      skipComma = false;
                  }
                  out.writeFieldName(propertyName);
                  try {
                      Object propertyValue = fieldInfo.get(object);
                      serializer.write(propertyValue);
                  } catch (IllegalAccessException e) {
                      throw new RuntimeException(e.getMessage(), e);
                  }
              }
      
              serializer.decrementIdent();
              serializer.setContext(object, fieldName, features);
              out.write('}');
          }
      }
      
      • 同時過濾掉age字段
         public static void main(String[] args) {
              Person person = new Person("John", "Doe", 30);
              String[] excludeProperties = {"age"};
              String json = JSON.toJSONString(person, new ExcludePropertyFilter(excludeProperties));
              System.out.println(json); 
          }
      
      posted @ 2023-08-10 16:39  張占嶺  閱讀(1252)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 丰满人妻被黑人猛烈进入| 中文字幕一区有码视三区| 亚洲一区二区在线av| 蜜臀久久综合一本av| 免费无码一区无码东京热| 国产乱子伦视频在线播放| 日韩免费无码一区二区三区| 日韩中文字幕亚洲精品| 亚洲精品国产av一区二区| 四虎影院176| 最新亚洲春色av无码专区| 九九热这里只有精品在线| 久热综合在线亚洲精品| 亚洲中文字幕无码一区无广告| 综合成人亚洲网友偷自拍| 亚洲精品乱码久久久久久按摩高清| 国产亚洲精品aaaa片app| 加查县| 亚洲国产日韩伦中文字幕| 国产午夜精品福利视频| 日韩人妻系列无码专区| 色欲av亚洲一区无码少妇| 少妇人妻偷人精品免费| 国产精品国产精品无卡区| 性欧美vr高清极品| 国产精品不卡区一区二| 国产精自产拍久久久久久蜜| 免费看无码自慰一区二区| 久久午夜夜伦鲁鲁片免费无码影院| 色欲久久久天天天综合网| 国产久久热这里只有精品| 国产精品视频亚洲二区| 欧洲免费一区二区三区视频| 日韩av在线一区二区三区| 亚洲永久一区二区三区在线| 亚洲精品乱码久久观看网| 精品一卡2卡三卡4卡乱码精品视频| 色一情一乱一伦麻豆| 国产午夜亚洲精品国产成人 | 亚洲色大成网站www在线| 久久精品国产亚洲av热一区|