java.lang.NullPointerException
at uk.co.blackpepper.bowman.GetterSetterMethodHandler.resolveCollectionLinkedResource(GetterSetterMethodHandler.java:139)
at uk.co.blackpepper.bowman.GetterSetterMethodHandler.resolveLinkedResource(GetterSetterMethodHandler.java:116)
at uk.co.blackpepper.bowman.GetterSetterMethodHandler.invoke(GetterSetterMethodHandler.java:90)
at com.test.client.bowman.Account_$$_jvst416_0.getAccountEmails(Account_$$_jvst416_0.java)
at com.test.client.bowman.Bowman.test(Bowman.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
package com.test.client.bowman;
import uk.co.blackpepper.bowman.annotation.LinkedResource;
import uk.co.blackpepper.bowman.annotation.RemoteResource;
import uk.co.blackpepper.bowman.annotation.ResourceId;
import java.net.URI;
import java.util.Set;
@RemoteResource("/accounts")
public class Account {
private URI id;
private String name;
private String timezone;
private boolean delegatedCompliance;
private Account parent;
private Set<AccountEmail> accountEmails;
@LinkedResource
public Set<AccountEmail> getAccountEmails() {
return accountEmails;
}
public void setAccountEmails(Set<AccountEmail> accountEmails) {
this.accountEmails = accountEmails;
}
@ResourceId
public URI getId() {
return id;
}
public String getName() {
return name;
}
public String getTimezone() {
return timezone;
}
public boolean isDelegatedCompliance() {
return delegatedCompliance;
}
public void setId(URI id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public void setDelegatedCompliance(boolean delegatedCompliance) {
this.delegatedCompliance = delegatedCompliance;
}
@LinkedResource
public Account getParent() {
return parent;
}
public void setParent(Account parent) {
this.parent = parent;
}
}
package com.test.client.bowman;
import uk.co.blackpepper.bowman.annotation.RemoteResource;
import uk.co.blackpepper.bowman.annotation.ResourceId;
import java.net.URI;
@RemoteResource("/accountEmails")
public class AccountEmail {
private URI id;
private String address;
@ResourceId
public URI getId() {
return id;
}
public void setId(URI id) {
this.id = id;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
My Test
@Test
public void test() throws URISyntaxException {
ClientFactory factory = Configuration.builder()
.setBaseUri("http://foo.bar.com/v1")
.setClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactoryBasicAuth(new HttpHost("foo.bar.com", 80, "http")))
.setRestTemplateConfigurer((template) ->
template.getInterceptors().add(new BasicAuthInterceptor("admin", "secret"))
)
.build()
.buildClientFactory();
Client<Account> accounts = factory.create(Account.class);
Account account = accounts.get(new URI("http://foo.bar.com/v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a"));
assertThat(account.getName(), is("Test"));
assertThat(account.getAccountEmails().iterator().next().getAddress(), is("[email protected]")); //This throws a NPE
}
GET /v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a
{
"id": "2dcd6f87-b6fd-4c20-8405-7e5432eb878a",
"name": "Test",
"timezone": "Australia/Hobart",
"new": false,
"_links": {
"self": {
"href": "https://foo.bar.com/v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a"
},
"account": {
"href": "https://foo.bar.com/v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a{?projection}",
"templated": true
},
"accountEmails": {
"href": "https://foo.bar.com/v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a/accountEmails"
},
"parent": {
"href": "https://foo.bar.com/v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a/parent"
}
}
}
/v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a/accountEmails
{
"_embedded": {
"accountEmails": [
{
"id": "a5f0de4f-dc83-4f5e-9b41-4dd5b5cd5094",
"address": "[email protected]",
"new": false,
"_links": {
"self": {
"href": "https://foo.bar.com/v1/accountEmails/a5f0de4f-dc83-4f5e-9b41-4dd5b5cd5094"
},
"accountEmail": {
"href": "https://foo.bar.com/v1/accountEmails/a5f0de4f-dc83-4f5e-9b41-4dd5b5cd5094"
},
"account": {
"href": "https://foo.bar.com/v1/accountEmails/a5f0de4f-dc83-4f5e-9b41-4dd5b5cd5094/account"
}
}
}
]
},
"_links": {
"self": {
"href": "https://foo.bar.com/v1/accounts/2dcd6f87-b6fd-4c20-8405-7e5432eb878a/accountEmails"
}
}
}