diff --git a/src/main/java/name/velikodniy/vitaliy/fixedlength/FixedLength.java b/src/main/java/name/velikodniy/vitaliy/fixedlength/FixedLength.java index 9b9a7c2..32e598a 100644 --- a/src/main/java/name/velikodniy/vitaliy/fixedlength/FixedLength.java +++ b/src/main/java/name/velikodniy/vitaliy/fixedlength/FixedLength.java @@ -53,7 +53,7 @@ private FixedFormatLine classToLineDesc(final Class 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; @@ -71,6 +71,17 @@ private FixedFormatLine classToLineDesc(final Class clazz) { return fixedFormatLine; } + List getAllFields(final Class clazz) { + if (clazz == null) { + return Collections.emptyList(); + } + + List result = new ArrayList<>(getAllFields(clazz.getSuperclass())); + List filteredFields = Arrays.stream(clazz.getDeclaredFields()).collect(Collectors.toList()); + result.addAll(filteredFields); + return result; + } + public FixedLength registerLineType(final Class lineClass) { lineTypes.add(classToLineDesc(lineClass)); return this; @@ -306,7 +317,8 @@ public String format(List lines) { for (T line : lines) { - Arrays.stream(line.getClass().getDeclaredFields()) + getAllFields(line.getClass()) + .stream() .filter( f -> f.getAnnotation(FixedField.class) != null