Class ObjectStringConversion


  • public class ObjectStringConversion
    extends StringConversion
    Object string conversion handling. Defines serialization handling for converting objects to and from a String value. The default is to just use the object toString() method for serialization and a constructor from a String value for deserialization. java.lang.String itself is a special case, with no added code used by default for either serializing or deserializing. java.lang.Object is also a special case, with no added code used by default for deserializing (the String value is used directly). Other classes must either implement toString() and a constructor from String, or use custom serializers and/or deserializers.
    Author:
    Dennis M. Sosnoski
    • Method Detail

      • genFromText

        public void genFromText​(ContextMethodBuilder mb)
                         throws org.jibx.runtime.JiBXException
        Generate code to convert String representation. The code generated by this method assumes that the String value has already been pushed on the stack. It consumes this and leaves the converted value on the stack.
        Specified by:
        genFromText in class StringConversion
        Parameters:
        mb - method builder
        Throws:
        org.jibx.runtime.JiBXException - Error if no de-serializer
      • genParseOptional

        public void genParseOptional​(boolean attr,
                                     ContextMethodBuilder mb)
                              throws org.jibx.runtime.JiBXException
        Generate code to parse and convert optional attribute or element. The code generated by this method assumes that the unmarshalling context and name information for the attribute or element have already been pushed on the stack. It consumes these and leaves the converted value (or converted default value, if the item itself is missing) on the stack.
        Specified by:
        genParseOptional in class StringConversion
        Parameters:
        attr - item is an attribute (vs element) flag
        mb - method builder
        Throws:
        org.jibx.runtime.JiBXException - if error in configuration
      • genParseRequired

        public void genParseRequired​(boolean attr,
                                     ContextMethodBuilder mb)
                              throws org.jibx.runtime.JiBXException
        Generate code to parse and convert required attribute or element. The code generated by this method assumes that the unmarshalling context and name information for the attribute or element have already been pushed on the stack. It consumes these and leaves the converted value on the stack.
        Specified by:
        genParseRequired in class StringConversion
        Parameters:
        attr - item is an attribute (vs element) flag
        mb - method builder
        Throws:
        org.jibx.runtime.JiBXException - if error in configuration
      • genToText

        public void genToText​(String type,
                              ContextMethodBuilder mb)
                       throws org.jibx.runtime.JiBXException
        Shared code generation for converting instance of type to String. This override of the base class method checks for serialization using the toString method and implements that case directly, while calling the base class method for normal handling. The code generated by this method assumes that the reference to the instance to be converted is on the stack. It consumes the reference, replacing it with the corresponding String value.
        Overrides:
        genToText in class StringConversion
        Parameters:
        type - fully qualified class name for value on stack
        mb - marshal method builder
        Throws:
        org.jibx.runtime.JiBXException - if error in configuration
      • genToOptionalText

        protected BranchWrapper genToOptionalText​(String type,
                                                  ContextMethodBuilder mb,
                                                  int extra)
                                           throws org.jibx.runtime.JiBXException
        Generate code to check if an optional value is not equal to the default. The code generated by this method assumes that the actual value to be converted has already been pushed on the stack. It consumes this, leaving the converted text reference on the stack if it's not equal to the default value.
        Specified by:
        genToOptionalText in class StringConversion
        Parameters:
        type - fully qualified class name for value on stack
        mb - method builder
        extra - count of extra values to be popped from stack if missing
        Returns:
        handle for branch taken when value is equal to the default (target must be set by caller)
        Throws:
        org.jibx.runtime.JiBXException - if error in configuration
      • isPrimitive

        public boolean isPrimitive()
        Check if the type handled by this conversion is of a primitive type.
        Specified by:
        isPrimitive in class StringConversion
        Returns:
        false to indicate object type
      • convertDefault

        protected Object convertDefault​(String text)
                                 throws org.jibx.runtime.JiBXException
        Convert text representation into default value object. For object types this just returns the text value.
        Specified by:
        convertDefault in class StringConversion
        Parameters:
        text - value representation to be converted
        Returns:
        converted default value object
        Throws:
        org.jibx.runtime.JiBXException - on conversion error
      • derive

        public StringConversion derive​(String type,
                                       String ser,
                                       String conv,
                                       String dser,
                                       String dflt)
                                throws org.jibx.runtime.JiBXException
        Derive from existing formatting information. This allows constructing a new instance from an existing format of the same or an ancestor type, with the properties of the existing format copied to the new instance except where overridden by the supplied values.
        Specified by:
        derive in class StringConversion
        Parameters:
        type - fully qualified name of class handled by conversion (null if inherited)
        ser - fully qualified name of serialization method (null if inherited)
        conv - fully qualified name of whitespace conversion method (null if inherited)
        dser - fully qualified name of deserialization method (null if inherited)
        dflt - default value text (null if inherited)
        Returns:
        new instance initialized from existing one
        Throws:
        org.jibx.runtime.JiBXException - if error in configuration information