Question

I have a simple pojo:

class UserId {
  String ssn;
  String otsId;
  Integer actorId;

  public UserId(String ssn, String otsId, Integer actorId) {
    this.ssn = ssn;
    this.otsId = otsId;
    this.actorId = actorId;
  }

  @Override
  public String toString() {
    return "[otsId=" + otsId + ", ssn=" + ssn + ", actorId=" + actorId + "]";
  }
}

And I want to extract for example all the ssn values to a List<String> from there. So just as an example I write:

public class UserIdTest {

  public static void main(String[] args) {
    List<UserId> list = new ArrayList<UserId>();
    list.add(new UserId("111111-1111", "12345678", new Integer(234589235)));
    list.add(new UserId("111111-1111", "12345678", new Integer(234589235)));
    list.add(new UserId("111111-1111", "12345678", new Integer(234589235)));

    getSsnList(list);
  }

  private static List<String> getSsnList(List<UserId> users) { 
    return extract(users, on(UserId.class).ssn); 
  }
}

and LambdaJ throws:

Exception in thread "main" ch.lambdaj.function.argument.ArgumentConversionException: Unable to convert the placeholder null in a valid argument
at ch.lambdaj.function.argument.ArgumentsFactory.actualArgument(ArgumentsFactory.java:76)
at ch.lambdaj.function.convert.ArgumentConverter.<init>(ArgumentConverter.java:29)
at ch.lambdaj.Lambda.extract(Lambda.java:1035)
at UserIdTest.getSsnList(UserIdTest.java:23)
at UserIdTest.main(UserIdTest.java:20)

This seems like a really basic operation so what am I missing here?

Was it helpful?

Solution

Lambdaj wraps your (non-final) classes with a Proxy and intercepts METHOD invocations on them. That means it cannot work on fields but only on methods like that:

extract(users, on(UserId.class).getSsn());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top