that helped very much... that was exactly the problem!
it obviously made sense I just oversaw it!
On Wednesday, September 12, 2012 12:54:54 PM UTC-4, Gustav wrote:
> Hello Laurent,
> first of all thanks for developing this great library... it really makes
> life easier.
> I have made everything work great and I have been able to receive a JSON
> response from
> the REST service I am hitting... the problem is that I get a nullpointer
> exception because
> the Json does not get deserialized OR maybe because it does not get mapped
> to the
> Model.
> Here is some code:
> I am trying to deserialize this:
> {
> "contracts": [
> {
> "id": 0,
> "name": "whatever",
> "epochs": [
> {
> "start": "2011-01-01T00:00:00Z",
> "end": "2011-12-31T00:00:00Z",
> "tariffs": [
> {
> "id": 0,
> "name": "t1",
> "cost": 20.0
> },
> {
> "id": 1,
> "name": "t2",
> "cost": 15.0
> }
> ]
> }
> ]
> }
> ]}
> As you see there are many arrays so what I did was this:
> I created 3 different classes...
> Contracts
> Epochs
> Tariffs
> public class Contracts {
> @JsonProperty("id")
> public Long id;
> @JsonProperty("name")
> public String name;
> @JsonProperty("epochs")
> public List<Epochs> epochs;
> public Long getId() {
> return id;
> }
> public void setId(Long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public List<Epochs> getEpochs() {
> return epochs;
> }
> public void setEpochs(List<Epochs> epochs) {
> this.epochs = epochs;
> }
> *************
> public class Epochs {
> @JsonProperty("start")
> public String startDate;
> @JsonProperty("end")
> public String endDate;
> @JsonProperty("tariffs")
> public List<Tariffs> tariffs;
> public String getStartDate() {
> return startDate;
> }
> public void setStartDate(String startDate) {
> this.startDate = startDate;
> }
> public String getEndDate() {
> return endDate;
> }
> public void setEndDate(String endDate) {
> this.endDate = endDate;
> }
> public List<Tariffs> getTariffs() {
> return tariffs;
> }
> public void setTariffs(List<Tariffs> tariffs) {
> this.tariffs = tariffs;
> }
> *************
> public class Tariffs {
> @JsonProperty("id")
> public Long id;
> @JsonProperty("name")
> public String name;
> @JsonProperty("cost")
> public Float cost;
> public Tariffs()
> {
> }
> public Long getId() {
> return id;
> }
> public void setId(Long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Float getCost() {
> return cost;
> }
> public void setCost(Float cost) {
> this.cost = cost;
> }
> }
> and then I have this on my interface
> @EndPoint("http://server.com")
> @Path("v2/{the.utility}")
> @HeaderParam(value = "Accept-Encoding", defaultValue = "gzip,deflate")
> @Consumes("application/json")
> @SocketTimeout(2000)
> @ConnectionTimeout(2000)
> @ResponseHandler(CustomResponse.class)
> public interface TheService{
> @Path("contract")
> public Contracts[] getContract();
> ************
> I call this like this:
> CRest crest = CRest.basicAuth(username, password).
> placeholder("the.utility","util").
> build();
> TheService api2 = crest.build(TheService.class);
> Contracts[] contract = api2.getContract();
> After doing this ... no matter if I use [] or List...
> contract = null
> Can you please help me..
> Thank you very much
> Gustav