开发者

How to convert from json string to CqlDuration?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜