jeudi 1 juillet 2021

Apply filter on all annotated fields of a POJO (Java)

Imagine that there are such kind of POJO classes, that just keep data:

public class Pojo() {

  @AnnotatedProp
  String someField;

  SubPojo someSubPojo;

  String someOtherFieldA;

  String someOtherFieldB;
}

public class SubPojo() {

  @AnnotatedProp
  String someSubField;

  Integer someOtherFieldC;
}

someField of Pojo and someSubField of SubPojo are marked special with the @AnnotatedProp property.

I'd like to modify an object of type Pojo. All String fields with @AnnotatedProp annotation should be modified. A "filter" should modify the values of these fields, e.g. replace some characters inside.

I tried with FieldUtils / simple reflection, but I ended up in stack overflows (the exception AND this forum).

What would be the best way to filter these fields?

Thanks for help.





Aucun commentaire:

Enregistrer un commentaire