[
https://issues.jboss.org/browse/IPROTO-120?page=com.atlassian.jira.plugin...
]
Nistor Adrian commented on IPROTO-120:
--------------------------------------
I'd rather add a new boolean flag in ProtoField annotation than piggyback on the
defaultValue. Something like {code}boolean strictDefaults() default false;{code}. Turning
that on would apply all rules laid out by the spec (which means empty string, 0 numerics,
empty collections, etc...). When this is turned off (default behaviour) we'll get
nulls. And if the field is not nullable (int vs Integer) we'll throw an error at
annotation processing time. Also, if the field is required=true we'll reject use of
strictDefaults and defaultValue because they cannot effectively do anything.
This will also be consistent with 4.2.x behaviour, so we do not have to publicly apologize
for it. But some might question why isnt's this behaviour the default one. Because
... compatibility :)
Null collection fields always unmarshalled as empty collection
implementation
-----------------------------------------------------------------------------
Key: IPROTO-120
URL:
https://issues.jboss.org/browse/IPROTO-120
Project: Infinispan ProtoStream
Issue Type: Bug
Reporter: Ryan Emerson
Assignee: Nistor Adrian
Priority: Major
The following Pojo always returns an empty collection after being unmarshalled,
regardless of whether {{stringList}} was null or empty when marshalled.
{code:java}
public class SomePojo {
@ProtoField(number = 1, collectionImplementation = ArrayList.class)
final List<String> stringList;
@ProtoFactory
public SomePojo(List<String> stringList) {
this.stringList = stringList;
}
}
{code}
This is because the generated marshaller always creates the collection instance before
attempting to read the collection content:
{code:java}
java.util.ArrayList __c$1 = new java.util.ArrayList();
boolean done = false;
while (!done) {
final int tag = $2.readTag();
switch (tag) {
case 0:
done = true;
break;
case 10: {
java.lang.String __v$1 = $2.readString();
__c$1.add(__v$1);
break;
}
default: {
if (!$2.skipField(tag)) done = true;
}
}
}
return new org.infinispan.query.dsl.embedded.testdomain.hsearch.SomePojo(__c$1);
{code}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)