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

com.sap.cloud.sdk.services.blockchain.multichain.utils.UnixTimestampDeserializer Maven / Gradle / Ivy

Go to download

Service integration of blockchain functionality (Beta release, still subject to change - up to discontinuation of module).

There is a newer version: 3.14.0
Show newest version
/*
 * Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
 */

package com.sap.cloud.sdk.services.blockchain.multichain.utils;

import java.io.IOException;
import java.time.Instant;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

/**
 * Jackson deserializer used to read a Unix timestamp (seconds since epoch) into an {@link Instant} object.
 */
public class UnixTimestampDeserializer extends JsonDeserializer
{
    /**
     * deserialize unix time to instants
     * 
     * @param jsonParser
     *            Json parser
     * @param deserializationContext
     *            DeserializationContext
     * @return hex value
     * @throws NumberFormatException
     *             multichainServiceException
     * @throws IOException
     *             IOException
     */
    @Override
    @Nonnull
    public Instant deserialize(
        @Nonnull final JsonParser jsonParser,
        @Nullable final DeserializationContext deserializationContext )
        throws NumberFormatException,
            IOException
    {
        final String timestamp = jsonParser.getText().trim();
        return Instant.ofEpochSecond((long) Integer.parseInt(timestamp));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy