io.getstream.chat.java.models.framework.UnixTimestampDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stream-chat-java Show documentation
Show all versions of stream-chat-java Show documentation
Stream Chat Java Client for backend integrations
The newest version!
package io.getstream.chat.java.models.framework;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.util.Date;
public class UnixTimestampDeserializer extends JsonDeserializer {
@Override
public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
String jsonString = jsonParser.readValueAs(String.class);
try {
return new Date(Long.parseLong(jsonString) * 1000);
} catch (NumberFormatException e) {
throw deserializationContext.instantiationException(
Date.class, "Unparseable date for unix timestamp: " + jsonString);
}
}
}