java - Constructor annotated with Jackson @JsonCreator not being called in POJO? -


i working web service stores pojos in mongodb. want make use of mongo's 'expireafterseconds' time live feature, clear out old documents in collection after period of time.

initially had implementation sent date rest service using following json:

{ "testindex": "testindex", "name": "hello", "date": "2016-05-09t11:00:39.639z" }

the above code created document in collection, , following annotation, deleted document after 10 seconds.

@indexed (expireafterseconds=10) private date date; 

after implementing code, decided wanted generate date on java side, meaning json follows:

{ "testindex": "testindex", "name": "hello" }

then have constructor in pojo using jsoncreator jackson

@jsoncreator public ttltestvo (@jsonproperty("testindex") string testindex, @jsonproperty("name") string name) {     this.testindex = testindex;     this.createdat = new date();     this.name = name; } 

from reading documentation here believe should flag constructor used when creating new object. testindex , name fields populated before. implementation, each time check document in mongo date value 'null'. if change text 1 of string values 'hello constructor', constructor appears not called initial text contained in json added database.

pojo

`

@document(collection = "test")public class ttltestvo {

@id private string _id;  @indexed private string testindex;  @indexed (expireafterseconds=10) private date createdat;  private string name;  @jsonignore public ttltestvo() {     // default }  @jsoncreator public ttltestvo (@jsonproperty("testindex") string testindex, @jsonproperty("name") string name) {     this.testindex = "hello constructor";     this.name = name; }  public string getid() {     return _id; }  public void setid(string _id) {     this._id = _id; }  public string getname() {     return name; }  public void setname(string name) {     this.name = name; }  public string gettestindex() {     return testindex; }  public void settestindex(string testindex) {     this.testindex = testindex; }  public date getdate() {     return createdat; }  public void setdate(date date) {     this.createdat = date; } ` 

after investigating more discovered issue lies spring framework implementation of @jsoncreator - removed imports org.springframework.cloud.cloudfoundry.com.fasterxml.jackson.annotation , replaced them com.fasterxml.jackson.annotation. above implementation functions expected.

i have been unable find explanation online why spring version isn't working, if has ideas please let me/ others know


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -