I am trying to find the best solution for a problem I have with mapping a simple bean structure that is being sent to a browser-based JavaScript application. The current requirement is to manage most of the display control on the old Java backend. Currently we have a service style layer that is producing value objects with no display logic built into them like:
public class Example1 {
String value1;
Boolean value2;
Example3 value3;
public String getValue1(){...}
public void setValue1(){...}
....
}
My goal is to be able to map a generic structure over all fields such that it adds the new display structure that is required by the front-end. I would like to manage only the original structure class (Example1 class) structure and simply set the extra values in a wrapper to the old service layer.
The generic structure would take the form of the following class:
public class Presentable<T> {
T value;
boolean visible = true;
boolean mandatory = false;
List<String> errors = new ArrayList<>();
public T getValue() {...}
public void setValue(T value) {...}
...
}
The end result would look something like the following, where value is equal to the value in the original structure:
public class Example2{
Presentable<String> value1;
Presentable<Boolean> value2;
Presentable<Example3> value3;
public Presentable<String> getValue1(){...}
public void setValue1(){...}
...
}
Is there a solution to this problem without writing an Example2 style class and copying in every single value? I am open to modification to the Example1 class as it does not affect consumers of the old service.
Thanks.