When making a POJO in Firebase, can you use ServerValue.TIMESTAMP?

前端 未结 6 1115
挽巷
挽巷 2020-11-30 02:51

When you\'re making a Plain Old Java Object that\'s meant to be serialized from and deserialized to Firebase, is there a way to use the ServerValue.TIMESTAMP va

6条回答
  •  天命终不由人
    2020-11-30 03:10

    Same solution, but I use this.

    @IgnoreExtraProperties
    public class FIRPost {
        Object timestamp;
    
        public FIRPost() {
            // Default constructor required for calls to DataSnapshot.getValue(FIRPost.class)
            this.timestamp = ServerValue.TIMESTAMP;
        }
    
        public Object getTimestamp() {
            return timestamp;
        }
    
        @Exclude
        public Long getTimestamp(boolean isLong) {
            if (timestamp instanceof Long) return (Long) timestamp;
            else return null;
        }
    }
    

提交回复
热议问题