How to fill all the fields in the class?

前端 未结 5 1663
时光说笑
时光说笑 2021-01-12 16:40

Suppose I have a class that has a lot of different fields. This class is a DTO and for testing purposes, I do not care about actual values, just it exists. Is there any tool

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 17:28

    Write a method with Introspector.getBeanInfo(object.getClass()).getPropertyDescriptors() in a small loop to fill fields as needed. You can recursively call this method to fill classes, collections etc.

    Other way is a XML deserialization using JAXB, XStream or Abraxas.

提交回复
热议问题