We have a POJO that is auto-generated with ~60 properties. This is generated with avro 1.4, which does not include getters/setters.
A library that we use to provide simple transformations between objects requires getter/setter-like methods in order to properly work.
Is there a way to replicate getters/setters without having to manually override the POJO and create all of the getters/setters manually?
public class BigGeneratedPojo {
public String firstField;
public int secondField;
...
public ComplexObject nthField;
}
public class OtherObject { …Run Code Online (Sandbox Code Playgroud) 我的代码库中有一个模式,看起来很像这样:我们正在处理来自队列的消息,然后将该消息传递到下一个队列。到目前为止的用例是我们处理和生成相同类型的消息。
public interface Processor<T> {
T process(T thing);
}
Run Code Online (Sandbox Code Playgroud)
该用例已演变为处理和生成不同类型的用例。此外,我们可能需要处理一种类型并生产一系列其他类型。
所以像:
public interface NewProcessor<I, O> {
O process(I thing;)
}
Run Code Online (Sandbox Code Playgroud)
并且将来可能需要类似的东西
public interface FutureProcessor<I, O1, O2> { //potentially N number of O
Pair<O1, O2> process(I thing);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:有没有办法比拥有三个单独的类更清晰地表达这种情况?我可以在这里使用一个很好的已知层次结构吗?
我们有第一种处理器的抽象用户,我希望每次添加新处理器时不必重新编写。它今天做了这样的事情:
public abstract AbstractModule<T> {
private Processor<T> processor;
public AbstractModule(Processor<T> processor) {
this.processor = processor;
}
T runModule(T input) {
// abstract validateInput(input);
T result = processor.process();
// record results
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
任何已知的模式或关于如何做到这一点的建议将不胜感激!