All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.backblaze.b2.json.B2JsonDurationHandler Maven / Gradle / Ivy

Go to download

The core logic for B2 SDK for Java. Does not include any implementations of B2WebApiClient.

There is a newer version: 6.3.0
Show newest version
/*
 * Copyright 2017, Backblaze Inc. All Rights Reserved.
 * License https://www.backblaze.com/using_b2_code.html
 */

package com.backblaze.b2.json;

import com.backblaze.b2.util.B2DateTimeUtil;

import java.io.IOException;
import java.time.Duration;

class B2JsonDurationHandler implements B2JsonTypeHandler {

    public Class getHandledClass() {
        return Duration.class;
    }

    public void serialize(Duration obj, B2JsonWriter out) throws IOException, B2JsonException {
        out.writeString(B2DateTimeUtil.durationString(obj.getSeconds()));
    }

    public Duration deserialize(B2JsonReader in, int options) throws B2JsonException, IOException {
        String str = in.readString();
        return deserializeUrlParam(str);
    }

    public Duration deserializeUrlParam(String urlValue) throws B2JsonException {
        return B2DateTimeUtil.parseDuration(urlValue);
    }

    public Duration defaultValueForOptional() {
        return null;
    }

    public boolean isStringInJson() {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy