忽略字段

由对象转换为json字符串时,增加@JSONField(serialize = _false_)即可

  1. import com.alibaba.fastjson.annotation.JSONField;
  2. import lombok.Data;
  3. @Data
  4. public class Person {
  5. @JSONField(serialize=false)
  6. private String id;
  7. private String name;
  8. private Integer age;
  9. }

带泛型的gson转换

  1. JsonElement labels = item.get("labels");
  2. if (ObjectUtils.isNotEmpty(labels)) {
  3. Type type = new TypeToken<List<String>>() {
  4. }.getType();
  5. List<String> labelList = GSON.fromJson(GSON.toJson(labels), type);
  6. if (ObjectUtils.isNotEmpty(labelList)) sheet.setLabels(String.join(" ", labelList));
  7. }