How to generate a computed property by method using gson?

Viewed 20

I have a abstract class below and annotated @SerializedName on methods, and expected that Gson should generate "findOffsetDuration" in final result, but it didn't. Anyway to generate that computed property?

    public abstract static class BaseSyncTimedReport extends TimedReport {
        protected Date findOffsetEndTime = new Date();
        protected Date findNextBatchEndTime = new Date();
        protected Date batchSyncEndTime = new Date();

        @SerializedName("findOffsetDuration")
        public long findOffsetDuration() {
            return Duration.between(startTime.toInstant(), findOffsetEndTime.toInstant()).toMillis();
        }

        @SerializedName("findNextBatchDuration")
        public long findNextBatchDuration() {
            return Duration.between(findOffsetEndTime.toInstant(), findNextBatchEndTime.toInstant()).toMillis();
        }

        @SerializedName("batchSyncDuration")
        public long batchSyncDuration() {
            return Duration.between(findNextBatchEndTime.toInstant(), batchSyncEndTime.toInstant()).toMillis();
        }
0 Answers
Related