通过绑定文件指定@XmlJavaTypeAdapter类? [英] Specify @XmlJavaTypeAdapter class via bindings file?

查看:53
本文介绍了通过绑定文件指定@XmlJavaTypeAdapter类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有第三方界面,提供与其API匹配的xsd文件。他们的一些映射不是Java,通常的布尔值为0& 1: - (

I have a 3rd party interface that supplies xsd files that matches their API. Some of their mappings are not quite Java, the usual boolean as 0 & 1 :-(

我想使用绑定文件为我的BooleanAdapter指定@XmlJavaTypeAdapter类,但到目前为止还没有快乐。

I'd like to use a bindings file to specify the @XmlJavaTypeAdapter class for my BooleanAdapter, but so far no joy.

绑定文件:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="http://java.sun.com/xml/ns/jaxws"
    jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0">
    <jaxb:bindings schemaLocation="GetUserDetailsResponse.xsd" node="/xs:schema" >
        <jaxb:globalBindings underscoreBinding="asWordSeparator" >
            <jaxb:serializable uid="1" />
            <jaxb:javaType name="java.lang.Boolean" xmlType="xs:boolean"
printMethod="mumble.bindings.BooleanAdapter.marshall" 
parseMethod="mumble.bindings.BooleanAdapter.unmarshall" />
        </jaxb:globalBindings>
    </jaxb:bindings>
</jaxb:bindings>

因为我正在使用maven来自POM的相关位:

And since I'm using maven the relevant bit from the POM:

<strict>false</strict>
<extension>true</extension>
<verbose>true</verbose>
<enableWrapperStyle>false</enableWrapperStyle>
<enableAsyncMapping>false</enableAsyncMapping>

我切换了enableWrapperStyle并且没有变化

I've toggled enableWrapperStyle and no change

我最终得到的是生成的错误类型的适配器:

What I end-up with is a generated Adapter of the wrong type:

import javax.xml.bind.annotation.adapters.XmlAdapter;
public class Adapter1
    extends XmlAdapter<String, Boolean>{
    public Boolean unmarshal(String value) {
        return (mumble.bindings.BooleanAdapter.unmarshall(value));
    }

    public String marshal(Boolean value) {
        return (mumble.bindings.BooleanAdapter.marshall(value));
    }
}

是否有一些绑定文件魔法我可以用来获取除掉生成的包装器并直接使用BooleanAdapter?

Is there some bindings file magic I can use to get rid of the generated wrapper and use the BooleanAdapter directly?

推荐答案

你需要使用< xjc:绑定配置中的javaType> 而不是< jaxb:javaType>
例如:

You need to use <xjc:javaType> in your binding config instead of <jaxb:javaType>. For example:

<xjc:javaType name="java.lang.Boolean" xmlType="xs:boolean"
              adapter="mumble.bindings.BooleanAdapter"/>

我知道我正在回答一个老问题,但我没有足够的声誉来写评论。

I understand I'm answering to an old question, but I don't have enough reputation to write a comment.

这篇关于通过绑定文件指定@XmlJavaTypeAdapter类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆