java - Implement a CustomIdHandler for jsonapi-converter -
i trying implement jsonapi spec using jsonapi-converter
library. part of it, trying code customidhandler
generate custom id. there support string or long id. in case need compound key need implement resourceidhandler
.
customidhandler
use case, in id combination of 2 properties. coursename
, courseid
.
courseidhandler.java
public class courseidhandler implements resourceidhandler { public courseidhandler() { } @override public string asstring(object identifier) { if (identifier != null) { return string.valueof(identifier); } return null; } @override public string fromstring(string source) { return source; } }
course.java
@type("course") public class course { @id(courseidhandler.class) private string id; private long coursename; private long courseid; public string getcoursename() { return coursename; } public void setcoursename(string coursename) { this.coursename = coursename; } public long getcourseid() { return courseid; } public void setcourseid(long courseid) { this.courseid = courseid; } public string getid() { return id; } public void setid(string id) { string myid = this.coursename + "_" + this.courseid; this.id = myid; } }
i trying set id in setter , expecting id set when courseidhandler resolved. null. pretty sure got wrong, , trying find correct approach above scenario.
Comments
Post a Comment