3 Replies Latest reply: Apr 25, 2012 11:31 AM by User738616-Oracle RSS

    Enums in POF ?

      I have a POF object called ResourceConnectionTokenPOF, inside that I have an enum 'Status' and a 'status' object of type 'enum->Status'.

      However when I try to put a POF of type ResourceConnectionTokenPOF on the cache it throws me an error message, I believe it is something to do with my usage

      of enum, can someone help ?

      How do i incorporate enum's in my POF, is there an example somewhere.

      Here is an abstract of my code:

      public class ResourceConnectionTokenPOF implements PortableObject {

      public static enum Status {

      private Status status;

      public static final int STATUS = 0;

      void ResourceConnectionTokenPOF() {

      public void readExternal(PofReader reader) throws IOException {
      this.status = (Status) reader.readObject(STATUS);

      public void writeExternal(PofWriter writer) throws IOException {
      writer.writeObject(STATUS, this.status);

      Edited by: Ankit Asthana on Apr 25, 2012 12:46 AM
        • 1. Re: Enums in POF ?
          Enum's are not POF serializable, so you'll need to find some alternative serialization form.

          One approach is to serialize them as strings:

          public void readExternal(PofReader reader) throws IOException {
          this.status = Status.valueOf(reader.readString(STATUS));

          public void writeExternal(PofWriter writer) throws IOException {
          writer.writeString(STATUS, this.status.name());
          • 2. Re: Enums in POF ?
            Other way would be to leave read/writeObject methods but configure ResourceConnectionTokenPOF$Status as user type and use EnumPofSerializer (the end result will be the same).
            • 3. Re: Enums in POF ?
              Hi Ankit,

              Alternatively, you can use this generic implementation for all your Enum objects:
              public class EnumSerializer implements PofSerializer {
              public void serialize(PofWriter writer, Object o) throws IOException {
              writer.writeString(0, ((Enum) o).name());
              public Object deserialize(PofReader reader) throws IOException {
              PofContext pofContext = reader.getPofContext();
              Class enumType = pofContext.getClass(reader.getUserTypeId());
              Enum enumValue = Enum.valueOf(enumType, reader.readString(0));
              return enumValue;
              Hope this helps!


              Edited by: user738616 on Apr 25, 2012 9:31 AM