How to generate JaxB-Classes with java.util.Optional?

夙愿已清 提交于 2019-12-03 06:51:53

Maybe you could find something more generic but i'm not sure if this is possible. Anyway you can still define custom Adapter for types you want to be optional.

Here is an example of Integer

First, create an Adapter

public final class IntegerOptionalAdapter extends OptionalAdapter<Integer>
{
} 

Then use this adapter in your binding

@XmlAttribute
@XmlJavaTypeAdapter(IntegerOptionalAdapter.class)
private Optional<Integer> someInteger;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!