I am trying to accept json data, and write into cassandra. One of the field is of type CqlDuration, in json, like:
{"down_duration": "1h"}
When I try to accept the data, convert into java class, I got error:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
Cannot construct instance of `com.datastax.oss.driver.api.core.data.CqlDuration`
(no Creators, like default constructor, exist):
no String-argument constructor/factory method to deserialize from String value ('1h')
It seems Jackson failed to convert string "1h" to CqlDuration, should I add开发者_如何学JAVA any Jackson annotation to solve this problem?
I just found that CqlDuration
's constructor is private, and there's a public static method from
can be used. so I added a setter:
public void setDownDuration(String downDuration) {
this.downDuration = CqlDuration.from(downDuration) ;
}
Problem solved.
精彩评论