Skip to content

Commit

Permalink
Update FixedLength.java
Browse files Browse the repository at this point in the history
  • Loading branch information
shotishu authored Apr 29, 2024
1 parent 7544dfe commit f001fd7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/name/velikodniy/vitaliy/fixedlength/FixedLength.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private FixedFormatLine<T> classToLineDesc(final Class<? extends T> clazz) {
if (annotation != null) {
fixedFormatLine.startsWith = annotation.startsWith();
}
for (Field field : clazz.getDeclaredFields()) {
for (Field field : getAllFields(clazz)) {
FixedField fieldAnnotation = field.getDeclaredAnnotation(FixedField.class);
if (fieldAnnotation == null) {
continue;
Expand All @@ -71,6 +71,17 @@ private FixedFormatLine<T> classToLineDesc(final Class<? extends T> clazz) {
return fixedFormatLine;
}

List<Field> getAllFields(final Class<?> clazz) {
if (clazz == null) {
return Collections.emptyList();
}

List<Field> result = new ArrayList<>(getAllFields(clazz.getSuperclass()));
List<Field> filteredFields = Arrays.stream(clazz.getDeclaredFields()).collect(Collectors.toList());
result.addAll(filteredFields);
return result;
}

public FixedLength<T> registerLineType(final Class<? extends T> lineClass) {
lineTypes.add(classToLineDesc(lineClass));
return this;
Expand Down Expand Up @@ -306,7 +317,8 @@ public String format(List<T> lines) {

for (T line : lines) {

Arrays.stream(line.getClass().getDeclaredFields())
getAllFields(line.getClass())
.stream()
.filter(
f ->
f.getAnnotation(FixedField.class) != null
Expand Down

0 comments on commit f001fd7

Please sign in to comment.