소스 검색

attempt better defaults for field set

tags/2.0.1
Jonathan Cobb 3 년 전
부모
커밋
48cea5d370
1개의 변경된 파일19개의 추가작업 그리고 2개의 파일을 삭제
  1. +19
    -2
      wizard-common/src/main/java/org/cobbzilla/wizard/model/entityconfig/EntityConfig.java

+ 19
- 2
wizard-common/src/main/java/org/cobbzilla/wizard/model/entityconfig/EntityConfig.java 파일 보기

@@ -1,5 +1,6 @@
package org.cobbzilla.wizard.model.entityconfig;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.models.media.Schema;
import lombok.Getter;
import lombok.Setter;
@@ -25,8 +26,10 @@ import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;

import static lombok.AccessLevel.PRIVATE;
import static org.apache.commons.lang3.reflect.FieldUtils.getAllFields;
import static org.cobbzilla.util.daemon.ZillaRuntime.*;
import static org.cobbzilla.util.json.JsonUtil.NOTNULL_MAPPER;
import static org.cobbzilla.util.json.JsonUtil.json;
@@ -219,8 +222,22 @@ public class EntityConfig {
final boolean hasIncludes = annotationStringArrayHasValues(schema.include());
final boolean hasExcludes = annotationStringArrayHasValues(schema.exclude());
if (!hasIncludes && !hasExcludes) {
// include all getters
entityFields.addAll(ReflectionUtil.toMap(instantiate(clazz)).keySet());
// sensible defaults
final Object thing = instantiate(clazz);
final List<String> defaultFields = Arrays.stream(getAllFields(clazz))
.filter(f -> f.getAnnotation(JsonIgnore.class) == null)
.filter(f -> f.getAnnotation(Transient.class) == null)
.filter(f -> {
try {
ReflectionUtil.get(thing, f.getName());
return true;
} catch (Exception e) {
return false;
}
})
.map(Field::getName)
.collect(Collectors.toList());
entityFields.addAll(defaultFields);
} else {
if (hasIncludes) entityFields.addAll(Arrays.asList(schema.include()));
if (hasExcludes) entityFields.removeAll(Arrays.asList(schema.exclude()));


불러오는 중...
취소
저장