JiBX
  1. JiBX
  2. JIBX-63

Cannot use deserializer "default" property with Java 1.5 enum

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.0-RC0
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      J2SE version 1.5.0_02-b09, Windows XP Professional (Service Pack 2)
    • Number of attachments :
      1

      Description

      I am able to use a Java 1.5 style enum for unmarshalling, like this:

      <value name="language" field="language" deserializer="Test.Language.valueOf"/>


      package Test;
      public enum Language
      {
      English, French, German
      }


      However, I get an binding compiler error when attempting to specify a default value for the enum:

      <value name="language" field="language" usage="optional" default="English" deserializer="Test.Language.valueOf"/>

      [bind] Using the following paths:
      [bind] C:\Borland\JBuilder2005\projects\JiBXBugExample\classes
      [bind] Using the following binding paths:
      [bind] mapping.xml
      [bind] Running binding compiler version jibx-rc0
      [bind] Error: Unable to load class Test.Language for converting default value of type Test.Language for value element at (line 4, col 118, in mapping.xml)
      [bind] Error running binding compiler
      [bind] org.jibx.runtime.JiBXException: Binding mapping.xml is unusable because of validation errors
      [bind] at org.jibx.binding.Utility.loadBinding(Utility.java:361)
      [bind] at org.jibx.binding.Utility.loadFileBinding(Utility.java:389)
      [bind] at org.jibx.binding.Compile.compile(Compile.java:294)
      ...

      It seems to have trouble loading my classes when trying to deal with the default value conversion. If I remove the "default" property, the error no longer occurs, though of course I lose the functionality that the "default" property provides.

      For your information, I am currently working around this bug by adding a method "fromString" to my enum classes. This method will return the desired default if it is passed a null parameter. Otherwise, it returns the result of valueOf provided by the enum itself.

      I have included an attachment, which contains a minimal project featuring this bug. It is a JBuilder project containing source files and an Ant build task.

        Activity

        Hide
        Dennis Sosnoski added a comment -

        This is just a usage error (actually, a pair of usage errors, the second one masked by the first). This first was that the classpath passed to the binding compiler had "." rather than the actual root directory for your compiled classes. Changing this to "$

        {dest}

        " corected this problem. The second issue was that you said "Test.Language.English" for the default, which is how you'd reference the enum value from Java but is not the text value. After changing this to just "English" everything ran okay.

        Show
        Dennis Sosnoski added a comment - This is just a usage error (actually, a pair of usage errors, the second one masked by the first). This first was that the classpath passed to the binding compiler had "." rather than the actual root directory for your compiled classes. Changing this to "$ {dest} " corected this problem. The second issue was that you said "Test.Language.English" for the default, which is how you'd reference the enum value from Java but is not the text value. After changing this to just "English" everything ran okay.
        Hide
        Matthieu Chartier added a comment -

        I'm not sure if this the best place to post, but this bug description fits best the issue I have.

        It might be more than a wrong usage. I get same error message in a similar situation (java5 enum) whenever a . (dot) occurs on the classpath.
        For instance: $

        {rootDir}/release1.2/classes

        Funny enough whenever all classes are packed up in a jar the error disappear, classpath becoming @{rootDir}

        /release1.2/myClasses.jar

        I tried to debug the binding, however it seems that the sources provided in the zip I got from sourceforge are not in sync with the classes in the various jibx jar files...

        Thanks for any help.

        Show
        Matthieu Chartier added a comment - I'm not sure if this the best place to post, but this bug description fits best the issue I have. It might be more than a wrong usage. I get same error message in a similar situation (java5 enum) whenever a . (dot) occurs on the classpath. For instance: $ {rootDir}/release1.2/classes Funny enough whenever all classes are packed up in a jar the error disappear, classpath becoming @{rootDir} /release1.2/myClasses.jar I tried to debug the binding, however it seems that the sources provided in the zip I got from sourceforge are not in sync with the classes in the various jibx jar files... Thanks for any help.

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Steffan Westcott
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: