[jboss-jira] [JBoss JIRA] (WFLY-6057) JAXB bindings of XmlJavaTypeAdapter are ignored

George Turner (JIRA) issues at jboss.org
Sun Jan 24 19:52:00 EST 2016


George Turner created WFLY-6057:
-----------------------------------

             Summary: JAXB bindings of XmlJavaTypeAdapter are ignored
                 Key: WFLY-6057
                 URL: https://issues.jboss.org/browse/WFLY-6057
             Project: WildFly
          Issue Type: Bug
          Components: Web Services
    Affects Versions: 10.0.0.CR5
            Reporter: George Turner
            Assignee: Alessio Soldano


I filed this problem in WF8, and I still cannot get it to work in WF10
Every xsd:date field prints as a xs:dateTime, and ignores by custom bindings.
Here is my setup:
binding.xjb
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          extensionBindingPrefixes="xjc" version="2.1">
    <globalBindings
        choiceContentProperty="true" generateIsSetMethod="true" typesafeEnumMaxMembers="2000">

        <xjc:javaType name="java.util.Date" xmlType="xs:date"
                  adapter="com.lmco.spacefence.infrastructure.webservices.util.XmlDateAdapter"/>
        <xjc:serializable/>

    </globalBindings>
</bindings>

package-info.java
@XmlJavaTypeAdapters({
    @XmlJavaTypeAdapter(value = XmlDateAdapter.class, type = java.util.Date.class),
    @XmlJavaTypeAdapter(value = XmlDatetimeAdapter.class, type = java.util.Calendar.class)
})
package com.lmco.spacefence.infrastructure.webservices.util;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;

XmlDateAdapter.java
package com.lmco.spacefence.infrastructure.webservices.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * Class is used to marshal/unmarshal String/Date in XML.
 */
public class XmlDateAdapter extends XmlAdapter<String, Date> {

    /**
     * Parses a Date value from the String.
     *
     * @param value to unmarshal
     * @return the parsed Date
     */
    @Override
    public Date unmarshal(String value) throws Exception {
        if (value == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.parse(value);
    }

    /**
     * Prints the Date value as a String.
     *
     * @param value to marshal
     * @return the String of the Date
     */
    @Override
    public String marshal(Date value) throws Exception {
        if (value == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(value);
    }
}

Field in generated source class from cxf-codegen-plugin using binding.xjb
 @XmlJavaTypeAdapter(XmlDateAdapter.class)
    protected Date createDate;



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the jboss-jira mailing list