Last active
October 15, 2019 12:56
-
-
Save mraible/abad8d78c1f053ec686b to your computer and use it in GitHub Desktop.
bindings.jxb to handle dates and namepace-prefix for NCPDP schemas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<bindings version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://java.sun.com/xml/ns/jaxb" | |
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd | |
http://jaxb2-commons.dev.java.net/namespace-prefix http://java.net/projects/jaxb2-commons/sources/svn/content/namespace-prefix/trunk/src/main/resources/prefix-namespace-schema.xsd"> | |
<globalBindings> | |
<serializable/> | |
<xjc:simple/> | |
<xjc:javaType adapter="com.company.app.utils.DateXmlAdapter" name="org.joda.time.DateTime" xmlType="xsd:date" /> | |
<xjc:javaType adapter="com.company.app.utils.DateTimeXmlAdapter" name="org.joda.time.DateTime" xmlType="xsd:dateTime" /> | |
</globalBindings> | |
<bindings schemaLocation="datatypes.xsd" node="/xsd:schema"> | |
<schemaBindings> | |
<package name="org.ncpdp.schema.datatypes"/> | |
</schemaBindings> | |
<bindings> | |
<namespace:prefix name="datatypes"/> | |
</bindings> | |
</bindings> | |
<bindings schemaLocation="pa-structures.xsd" node="/xsd:schema"> | |
<schemaBindings> | |
<package name="org.ncpdp.schema.pa_structures"/> | |
</schemaBindings> | |
<bindings> | |
<namespace:prefix name="pa-structures"/> | |
</bindings> | |
</bindings> | |
<bindings schemaLocation="script.xsd" node="/xsd:schema"> | |
<schemaBindings> | |
<package name="org.ncpdp.schema.script"/> | |
</schemaBindings> | |
<bindings> | |
<namespace:prefix name="script"/> | |
</bindings> | |
</bindings> | |
<bindings schemaLocation="specialized.xsd" node="/xsd:schema"> | |
<schemaBindings> | |
<package name="org.ncpdp.schema.specialized"/> | |
</schemaBindings> | |
<bindings> | |
<namespace:prefix name="specialized"/> | |
</bindings> | |
</bindings> | |
<bindings schemaLocation="structures.xsd" node="/xsd:schema"> | |
<schemaBindings> | |
<package name="org.ncpdp.schema.structures"/> | |
</schemaBindings> | |
<bindings> | |
<namespace:prefix name="structures"/> | |
</bindings> | |
</bindings> | |
<bindings schemaLocation="transport.xsd" node="/xsd:schema"> | |
<schemaBindings> | |
<package name="org.ncpdp.schema.transport"/> | |
</schemaBindings> | |
<bindings> | |
<namespace:prefix name="transport"/> | |
</bindings> | |
</bindings> | |
</bindings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company.app.utils; | |
import org.joda.time.DateTime; | |
import org.joda.time.format.DateTimeFormatter; | |
import org.joda.time.format.ISODateTimeFormat; | |
import javax.xml.bind.annotation.adapters.XmlAdapter; | |
public class DateTimeXmlAdapter extends XmlAdapter<String, DateTime> { | |
private static final DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC(); | |
@Override | |
public DateTime unmarshal(String value) { | |
return formatter.parseDateTime(value); | |
} | |
@Override | |
public String marshal(DateTime value) { | |
return formatter.print(value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company.app.utils; | |
import org.joda.time.DateTime; | |
import org.joda.time.format.DateTimeFormatter; | |
import org.joda.time.format.ISODateTimeFormat; | |
import javax.xml.bind.annotation.adapters.XmlAdapter; | |
public class DateXmlAdapter extends XmlAdapter<String, DateTime> { | |
private static final DateTimeFormatter formatter = ISODateTimeFormat.date().withZoneUTC(); | |
@Override | |
public DateTime unmarshal(String v) throws Exception { | |
return formatter.parseDateTime(v); | |
} | |
@Override | |
public String marshal(DateTime v) throws Exception { | |
return formatter.print(v); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment