com.numeralasia.payment.model.util.JsonDateTimeSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of payment-model Show documentation
Show all versions of payment-model Show documentation
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
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();
}
}
}
}