polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mingzhou Zhuang (JIRA)" <j...@apache.org>
Subject [jira] [Created] (ZEST-142) Enum Property in EntityComposite serialization error
Date Fri, 15 Apr 2016 08:31:25 GMT
Mingzhou Zhuang created ZEST-142:
------------------------------------

             Summary: Enum Property in EntityComposite serialization error
                 Key: ZEST-142
                 URL: https://issues.apache.org/jira/browse/ZEST-142
             Project: Zest
          Issue Type: Bug
    Affects Versions: 2.1
            Reporter: Mingzhou Zhuang
            Priority: Critical


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

{code}
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();
            }
        }
    }




{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message