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

com.numeralasia.payment.model.util.JsonDateDeserializer Maven / Gradle / Ivy

Go to download

Payment-Model Model Class for representating an object for payment through midtrans, this is used for accessing model api if you use Numeral Asia payment service

There is a newer version: 1.0.49
Show newest version
package com.numeralasia.payment.model.util;

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 org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JsonDateDeserializer extends JsonDeserializer {
    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {

        SimpleDateFormat format = new SimpleDateFormat(DateAppConfig.API_DATE);
        String date = jsonParser.getText();
        try {
            if(StringUtils.isEmpty(date)){
                return null ;
            }
            return format.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null ;
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy