开发者

Abstract mapping with custom JiBX marshaller

I have created a custom JiBX marshaller and verified it works. It works by doing something like the following:

<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>

However I need to create multiple marshallers for different HashMaps. So I tried to reference it with abstract mapping like this:

<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="co开发者_如何学Pythonm.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>

However when doing so, when I attempt to build the binding, I receive the following:

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

My guess is that either I'm missing something I need to implement to enable my custom marshaller for abstract mapping, or custom marshallers do not support abstract mapping.

I have found the IAbstractMarshaller interface in the JiBX API (http://jibx.sourceforge.net/api/org/jibx/runtime/IAbstractMarshaller.html), however the documentation seems unclear to me on if this is what I need to implement, as well as how it works if so. I have not been able to find an implementation of this interface to work off of as an example.

My question is, how do you do abstract mapping with custom marshallers (if it's possible)? If it is done via the IAbstractMarshaller interface, how does it work and/or how should I implement it?


I'm not sure whether the IAbstractMarshaller interface is what you're looking for; the docs are a bit unclear. If you don't mind a little repetition, you can specify the marshaller directly on your structure mapping, which should get the desired result (separate mappings for 'configuration' and 'overrides'):

<binding xmlns:tns="http://foobar.com/foo" direction="output">
  <namespace uri="http://foobar.com/foo" default="elements"/>
  <mapping name="context" class="com.foobar.Context">
    <structure map-as="configuration" field="configuration" marshaller="com.foobar.Marshaller1"/>
    <structure map-as="overrides" field="overrides" marshaller="com.foobar.Marshaller2"/>
  </mapping>
</binding>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜