polygene-dev mailing list archives

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

    [ https://issues.apache.org/jira/browse/ZEST-142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15242683#comment-15242683
] 

Niclas Hedhman commented on ZEST-142:
-------------------------------------

I have taken a quick look, and the reason is;

for ValueComposite deserialization, the entire value is deserialized in one go. For EntityComposites,
each Property is deserialized individually, and the top level method (deserializeRoot) doesn't
deal with Enums (no deserializer registered and not an Array) and simply concludes that it
is a Complex type.

Not sure why this works if it is OrgJson instead.

This shouldn't take too long.

> 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
>              Labels: bug
>
> 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