dimanche 21 avril 2019

Dynamic class creation with Fields from other classes

Example:

public class MyObject{
    @SerializedName("hello")
    @NotNull @MaxLength(256) @NotEmpty
    private String hello;
}

public class MyOtherObject{
    @SerializedName("world")
    @NotNull @MaxLength(512) @NotEmpty
    private String world;
}

How to dynamically generate a class MyDynamicHelloWorldObject such that it becomes the equivalent of:

public class MyDynamicHelloWorldObject{
    @SerializedName("hello")
    @NotNull @MaxLength(256) @NotEmpty
    private String hello;

    @SerializedName("world")
    @NotNull @MaxLength(512) @NotEmpty
    private String world;
}

Looking for solutions because copying and pasting is going to lead to errors, especially when code is changed in the future.





Aucun commentaire:

Enregistrer un commentaire