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

com.numeralasia.payment.model.util.JsonDateTimeSerializer 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.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.numeralasia.payment.model.util.Constant;

import java.text.SimpleDateFormat;
import java.util.Date;

public class JsonDateTimeSerializer extends JsonSerializer {


    private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat(Constant.API_DATE_TIME_FORMAT);
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.API_DATE_FORMAT);
    private static final SimpleDateFormat dateTimeZoneFormatter = new SimpleDateFormat(Constant.DATE_TIMEZONE_FORMAT);

    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) {

        boolean success = false ;
        if(!success){
            try {
                if(date==null){
                    return;
                }
                String formattedDate = dateTimeZoneFormatter.format(date);
                jsonGenerator.writeString(formattedDate);
                success = true ;
            }catch (Exception e){
//                e.printStackTrace();
            }
        }
        if(!success){
            try {
                if(date==null){
                    return;
                }
                String formattedDate = dateTimeFormat.format(date);
                jsonGenerator.writeString(formattedDate);
                success = true ;
            }catch (Exception e){
//                e.printStackTrace();
            }
        }
        if(!success){
            try {
                if(date==null){
                    return;
                }
                String formattedDate = dateFormat.format(date);
                jsonGenerator.writeString(formattedDate);
                success = true ;
            }catch (Exception e){
//                e.printStackTrace();
            }
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy