I was following this tutorial for Android REST client, but instead of using greeting service, I used my own REST HATEOAS service which returns HAL+JSON in this format:
"name" : "new task",
"description" : "this is new task",
"_links" : {
"self" : {
"href" : "http://test/tasks/1"
},
"item" : {
"href" : "http://test/tasks/1/item"
},
}
I get this error at runtime:
Could not read JSON: Unrecognized field "_links"
(class com.test.mobile.model.Task), not marked as ignorable
(3 known properties: "name", "item", "description"])
At this line in MainActivity:
Task task = restTemplate.getForObject(url, Task.class);
I would copy/paste all the code, but it's identical to one from tutorial, except it has this two classes instead of greeting:
public class Task {
private String name;
private String description;
private Item item;
public Task() {
}
/*getters and setters*/
}
public class Item {
private String name;
private Set<Task> tasks = new HashSet<Task>(0);
public Item() {
}
/*getters and setters*/
}
I was looking for some tutorial or code with HATEOAS but found nothing of relevance.
How can I modify my code for spring to be able to parse HATEOAS _links?
You dont have a field for "_links" you need to ingnore it OR add a little class that would take that object.
How you can solve it? Simply Add another nested class. be aware it became ugly fast, i have just explained the idea.