Uploaded image for project: 'Polygene'
  1. Polygene
  2. POLYGENE-142

Enum Property in EntityComposite serialization error

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 3.0.0
    • Labels:
    • Flags:
      Important

      Description

      TestValue as value composite, it's ok.
      TestValue as entity composite, fail?

      public enum TestEnum {
          A, B, C, D
      }
      
      public interface TestValue {
          Property<Double> price();
      
          Property<TestEnum> testenum();
      }
      
      public static void main(String[] args) throws ActivationException, AssemblyException, UnitOfWorkCompletionException, JsonProcessingException {
              SingletonAssembler assembler = new SingletonAssembler() {
                  @Override
                  public void assemble(ModuleAssembly module_)
                          throws AssemblyException {
                      module_.values(TestValue.class);    // Value
                      module_.entities(TestValue.class);  // Entity
                      module_.services(JacksonValueSerializationService.class)
                              .taggedWith(ValueSerialization.Formats.JSON)
                              .visibleIn(Visibility.application)
                              .instantiateOnStartup();
                      module_.services(MemoryEntityStoreService.class);
                      module_.services(UuidIdentityGeneratorService.class);
                  }
              };
      
              Module module = assembler.module();
              ValueSerialization serialization = module.findService(ValueSerialization.class)
                      .get();
      
              TestValue value;
              {
                  ValueBuilder<TestValue> builder = module.newValueBuilder(TestValue.class);
                  builder.prototype().price().set(23.45);
                  builder.prototype().testenum().set(TestEnum.B);
                  value = builder.newInstance();
                  _sLogger.info("value {}, {}, {}", value, value.price().get(), value.testenum().get());
                  System.out.println(serialization.serialize(value)); // ok
                  value = serialization.deserialize(TestValue.class, serialization.serialize(value)); // ok
                  _sLogger.info("de value {}, {}, {}", value, value.price().get(), value.testenum().get());
              }
              {
                  String valueId = "abcdefg";
                  {
                      UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("create"));
                      EntityBuilder<TestValue> builder = uow.newEntityBuilder(TestValue.class, valueId);
                      builder.instance().price().set(45.67);
                      builder.instance().testenum().set(TestEnum.A);
                      value = builder.newInstance();
                      try {
                          uow.complete();
                      } catch (Exception e_) {
                          uow.discard();
                          e_.printStackTrace();
                      }
                  }
                  {
                      UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("create"));
                      value = uow.get(TestValue.class, valueId);
                      System.out.println(value.price().get());
                      System.out.println(value.testenum().get()); // FAIL
                      uow.discard();
                  }
              }
          }
      
      
      
      
      

        Attachments

          Activity

            People

            • Assignee:
              niclas Niclas Hedhman
              Reporter:
              zhuangmz Mingzhou Zhuang
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: