Yes, the serializer/deserializers match up with JAXB's print/parse methods. I think they're actually a little more flexible, in that Object type conversions by default use the toString() method of the object to serialize, and a constructor from String (assuming one is defined) to deserialize. If you just need to override one side of this default handling you can specify just a serializer or just a deserializer.

 - Dennis

Jay Blanton wrote:

Wow...that was easy. I figured it out...thanks for pointing me to the serializer/deserializer:

public class DateTimeSerializer {


public static DateTime deserializeDateTime(String dateTime) throws XmlBinderException{
        DateTime date = null;
        try {
date = DateTimeHelper.getDateTimeFromFormat(dateTime, DateTime.YYYY_MM_DD);
        }
        catch (ParseException e) {
            throw new XmlBinderException(e);
        }
        return date;
    }

    public static String serializeDateTime(DateTime dateTime) {
        return dateTime.getDateTimeFormat(DateTime.YYYY_MM_DD);
    }

}

With binding.xml:

<binding direction="both" forwards="false" package="foo.jibx" value-style="element" > <format type="foo.DateTime" serializer="foo.jibx.DateTimeSerializer.serializeDateTime" deserializer="foo.jibx.DateTimeSerializer.deserializeDateTime"/>
  <mapping class="foo.DiagnosisTO" name="Diagnosis">
    <value name="codeType" field="codeType"/>
    <value name="code" field="code"/>
    <value field="date" name="date"/>
  </mapping>
</binding>

This successfully now converts between XML and Java Object....AWESOME!!!!!!! This was soooooo easy.

Thanks for your help!!!!

-jay

On 12/19/05, *Jay Blanton* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    This is a segment of my XML that uses a custom class:

    <Diagnosis>
         <codeType>123</codeType>
         <code>Blah</code>
         <date>2005-12-04</date>
    </Diagnosis>

    The date element is really just the CCYY-MM-DD (required format
    for xs:date) and needs to be converted into:

    public class DiagnosisTO extends BaseTO implements ImageTO {
        private DateTime date;
        private String code;
        private String codeType;
        .........

    The DateTime object just does the general date comparison,
    conversion from calendar, and so on.  So I can create a DateTime
    object with the following constructor:

    new DateTime(Calendar c) or new DateTime(TimeZone tz) or new
    DateTime(String dbdate) or others

    And I convert from DateTime into date String (in CCYY-MM-DD format
    for xs:date):

    dateTime.getDateTimeFormat(DateTime.YYYY_MM_DD)

    In JAXB (just as a sample, I did the following:

    public class DateTimeDatatypeConverter {
        /**
         * @param value param
         *
         * @return returned
         */
        public static DateTime parseStringToDateTime(String value) {
            return new DateTime(DatatypeConverter.parseDate(value));
        }

        /**
         * @param value param
         *
         * @return returned
         */
        public static String printDateTimeToString(DateTime value) {
            return
    DatatypeConverter.printString(value.getDateTimeFormat(DateTime.YYYY_MM_DD));
        }
    }

    My Type Safe Enumerations work the same way, here is a code snippet:

    <PatientConditionInformation>
        <conditionCategory>77</conditionCategory>
        <conditionResponse>Y</conditionResponse>
        <conditionIndicator>01</conditionIndicator>
    </PatientConditionInformation>

    All these subelements refer to a value in the TypeSafeEnumeration.
    Class example:

    public class PatientConditionCategoryType extends
    AbstractTypeSafeEnumeration {
        public static final PatientConditionCategoryType
    AMBULANCE_CERT = new PatientConditionCategoryType("07", "Ambulance
    Certification");
        public static final PatientConditionCategoryType
    OXYGEN_THERAPY_CERT = new PatientConditionCategoryType("11",
    "Oxygen Therapy Certification");
        public static final PatientConditionCategoryType MENTAL_STATUS
    = new PatientConditionCategoryType("77", "Mental Status");

    With the pairing being (value, displayValue).

    JAXB Converter example:

    public class PatientConditionCategoryDatatypeConverter {
        /**
         * @param value param
         *
         * @return returned
         */
        public static PatientConditionCategoryType
    parseStringToPatientConditionCategory(String value) {
            return
    PatientConditionCategoryType.getType(DatatypeConverter.parseString(value));
        }


        /**
         * @param value param
         *
         * @return returned
         */
        public static String
    printPatientConditionCategoryToString(PatientConditionCategoryType
    value) {
            return DatatypeConverter.printString(value.getValue());
        }
    }

    Sorry for the overload of information....I am just totally stoked
    to get this working and very much appreciate your insight.

    Thanks,

    Jay



    On 12/19/05, *Thomas Jones-Low* <[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>> wrote:

        Jay Blanton wrote:

I am reading how to do this in JiBX, but I am a little
        confused on the
class.  I believe the binding file would say something like this
(created through the binding generator):

                I've built a some of these as well, so I'll offer some
        of my examples
        and advice.

<?xml version="1.0" encoding="UTF-8"?>
<binding forwards="false" value-style="attribute">
  <mapping class="foo.DateTime" marshaller="DateTimeMapper"
unmarshaller="foo.Date"/>
  <mapping class="foo.DiagnosisTO" name="diagnosis">
    <structure field="date" usage="optional" name="date"/>
    <value style="element" name="code" field="code"
        usage="optional"/>
    <value style="element" name="code-type" field="codeType"
usage="optional"/>
  </mapping>
</binding>

Problem is that I don't totally understand how to use the
marshal/unmarshal methods described in:

                If you could post an example of the xml to be
        (un)marshalled, it would
        help.

                For the date/time, you may be going too far into the
        examples. If the
        DateTime is a single field in the XML you may want to look at
        using
        Serializer/Deserilzers.

http://jibx.sourceforge.net/tutorial/binding-custom.html#figure21
        <http://jibx.sourceforge.net/tutorial/binding-custom.html#figure21>

In the marshal method (for JiBX), the Object parameter would
        actually be
representing my DateTime object and I would be creating the
        XML chunk
where this attribute lives in the Object/XML file.  Is that
        correct?  I
ask because I see the startTagAttributes or endTag.  Any
        suggestions?

Also, for a global definition, what does the following
        information stand
for:

m_uri = null;
m_index = 0;
m_name = null;


                m_uri is the URI if the XML namespace. If your XML
        file uses multiple
        namespaces, this is the namespace URI for the element.

                m_index is the index of the element name in the JiBX
        internal data
        structures.

                m_name is the name of the element which encloses your
        custom structure.
        E.g. if your xml uses <datetime> xxxxx </datetime>, this would be
        "datetime".

                These are largely used as magic cookies. You should
        never need to
        change them, juss pass them back to the JiBX code.

I see it in the HashMapper example and I can see that it is
        referenced
in the marshal/unmarshal methods.

This is my first custom mapper in JiBX and I am sure once I
        write one,
the other ones will be totally easy.


                You are correct, writing the mappers isn't difficult.
        Cut and paste the
        class constructors and the isExtension method from the
        example. You will
        need to write the following methods:

             public void marshal(Object obj, IMarshallingContext ictx)
                 throws JiBXException
             public Object unmarshal(Object obj, IUnmarshallingContext
        ictx)
                 throws JiBXException


                If you had an XML example I could show you some code.

        --
                Thomas Jones-Low            Softstart Services Inc.
                [EMAIL PROTECTED]
        <mailto:[EMAIL PROTECTED]>      JobScheduler for Oracle
                Ph: 802-398-1012            http://www.softstart.com


        -------------------------------------------------------
        This SF.net email is sponsored by: Splunk Inc. Do you grep
        through log files
        for problems?  Stop!  Download the new AJAX search engine that
        makes
        searching your log files as easy as surfing
        the  web.  DOWNLOAD SPLUNK!
        http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
        <http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click>
        _______________________________________________
        jibx-users mailing list
        [email protected]
        <mailto:[email protected]>
        https://lists.sourceforge.net/lists/listinfo/jibx-users




-- jay blanton
    [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
    (c) 916-715-1529




--
jay blanton
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
(c) 916-715-1529



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to