Hi,
given the value type
public interface SystemUser
{
Property<String> username();
Property<String> password();
}
public interface SystemUserComposite extends ValueComposite,SystemUser {}
The following works fine:
SingletonAssembler sa = new SingletonAssembler()
{
@Override
public void assemble( ModuleAssembly module )
throws AssemblyException
{
module.addValues( SystemUserComposite.class );
}
};
final String json = "{username:\"snoopy\",password:\"VeRySeCrEt\"}";
SystemUser val = sa.valueBuilderFactory().newValueFromJSON(
SystemUser.class, json );
String jsonized = ((Value)val).toJSON();
assert json == jsonized;
System.out.println(jsonized);
But when I use explicit property types in SystemUser like
public interface Username extends Property<String> {}
public interface Password extends Property<String> {}
public interface SystemUser
{
Username username();
Password password();
}
the *newValueFromJSON* throws an exception
Exception in thread "main"
org.qi4j.api.constraint.ConstraintViolationException: Constraint
violation in .<unknown> for method username with constraint not
optional, for value 'null'
at
org.qi4j.runtime.property.AbstractPropertyModel.checkConstraints(AbstractPropertyModel.java:203)
at
org.qi4j.runtime.property.AbstractPropertyModel.checkConstraints(AbstractPropertyModel.java:215)
at
org.qi4j.runtime.property.AbstractPropertiesModel.checkConstraints(AbstractPropertiesModel.java:255)
at
org.qi4j.runtime.composite.AbstractStateModel.checkConstraints(AbstractStateModel.java:99)
at
org.qi4j.runtime.value.ValueModel.checkConstraints(ValueModel.java:109)
at
org.qi4j.runtime.value.ValueBuilderInstance.newInstance(ValueBuilderInstance.java:104)
at
org.qi4j.runtime.types.ValueCompositeType.fromJSON(ValueCompositeType.java:163)
at
org.qi4j.runtime.structure.ModuleInstance$ValueBuilderFactoryInstance.newValueFromJSON(ModuleInstance.java:535)
Trying it the other way round, i.e. build the value instance by 'hand'
and then jsonize it with
ValueBuilder<SystemUser> v =
sa.valueBuilderFactory().newValueBuilder( SystemUser.class );
SystemUser p = v.prototype();
p.username().set( "snoopy" );
p.password().set( "NoSeCrEt" );
SystemUser val = v.newInstance();
String jsonized = ((Value) val).toJSON();
System.out.println( jsonized );
*toJSON()* results in "{}"
I expected both versions to work in the same way. Wrong thought or bug?
Cheers,
Georg
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev