com.sap.cloud.sdk.services.blockchain.multichain.utils.UnixTimestampDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blockchain Show documentation
Show all versions of blockchain Show documentation
Service integration of blockchain functionality (Beta release, still subject to change - up to discontinuation of module).
/*
* 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));
}
}