
com.megaport.api.util.DateDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client Show documentation
Show all versions of client Show documentation
This library is a Java wrapper for the Megaport API.
The newest version!
package com.megaport.api.util;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by chris.zhao on 5/05/15.
*/
public class DateDeserializer extends JsonDeserializer {
@Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
try {
Long dateInMillisecond = jp.getLongValue();
return new Date(dateInMillisecond);
} catch (Exception e) {
try {
return new SimpleDateFormat("dd/MMM/yy").parse(jp.getText());
} catch (ParseException e1) {
return null;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy