ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Pitts" <Daniel.Pi...@cnet.com>
Subject RE: Map nullValue to empty collection
Date Fri, 09 Feb 2007 18:38:16 GMT
Depending on whether you need to be able to "add/remove" from the
Objects list after its set:

public void setObjects(List<Object> objects) {
    this.objects = objects == null ? Collections.emptyList() : objects;
} 
// or
public void setObjects(List<Object> objects) {
    this.objects = objects == null ? new ArrayList<Object>() : objects;
} 


-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Stephane Bailliez
Sent: Friday, February 09, 2007 1:49 AM
To: user-java@ibatis.apache.org
Subject: Map nullValue to empty collection


I have a setter which does no accept null values for a list, ie:

public void setObjects(List<Object> objects){
    if (objects == null) throw new NullPointerException("null not
permitted");
    this.objects = objects;
}

I did not find yet any decent way to map a nullvalue to an empty list, I
was thinking of using a specific TypeHandlerCallback on this property on
the result map but did not go this route yet.

For now dumbest thing I could do was to remove the check and do nothing
if objects is null, other possibility include an intermediate holder
object...or ?

Any suggestions welcome.

-- stephane


Mime
View raw message