我创建了一个自定义 JiBX 编组器并验证了它的工作原理。它通过执行以下操作来工作:
<binding xmlns:tns="http://foobar.com/foo" direction="output">
<namespace uri="http://foobar.com/foo" default="elements"/>
<mapping class="java.util.HashMap" marshaller="com.foobar.Marshaller1"/>
<mapping name="context" class="com.foobar.Context">
<structure field="configuration"/>
</mapping>
</binding>
但是我需要为不同的 HashMaps 创建多个编组器。所以我尝试用这样的抽象映射来引用它:
<binding xmlns:tns="http://foobar.com/foo" direction="output">
<namespace uri="http://foobar.com/foo" default="elements"/>
<mapping abstract="true" type-name="configuration" class="java.util.HashMap" marshaller="com.foobar.Marshaller1"/>
<mapping abstract="true" type-name="overrides" class="java.util.HashMap" marshaller="com.foobar.Marshaller2"/>
<mapping name="context" class="com.foobar.Context">
<structure map-as="configuration" field="configuration"/>
<structure map-as="overrides" field="overrides"/>
</mapping>
</binding>
但是,这样做时,当我尝试构建绑定时,我会收到以下信息:
Error during code generation for file "E:\project\src\main\jibx\foo.jibx" - this may be due to an error in your binding or classpath, or to an error in the JiBX code
我的猜测是,要么我遗漏了一些我需要实现的东西来启用我的自定义编组器进行抽象映射,要么自定义编组器不支持抽象映射。
我在 JiBX API ( http://jibx.sourceforge.net/api/org/jibx/runtime/IAbstractMarshaller.html ) 中找到了 IAbstractMarshaller 接口,但是我似乎不清楚这是否是我需要实现的文档,以及它是如何工作的。作为示例,我无法找到该接口的实现。
我的问题是,您如何使用自定义编组器进行抽象映射(如果可能的话)?如果它是通过 IAbstractMarshaller 接口完成的,它是如何工作的和/或我应该如何实现它?