io.apimatic.core.utilities.DateHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
A library that contains core logic and utilities for consuming REST APIs using Java SDKs generated by APIMatic.
package io.apimatic.core.utilities;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.fasterxml.jackson.core.JsonGenerator;
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 com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* This is a utility class for Date operations.
*/
public class DateHelper {
protected DateHelper() {}
/**
* Parse a simple date string to a LocalDate object.
* @param date The date string.
* @return The parsed LocalDate object.
*/
public static LocalDate fromSimpleDate(String date) {
return LocalDate.parse(date);
}
/**
* Convert a LocalDate object to a string.
* @param value The LocalDate object to convert.
* @return The converted Strings.
*/
public static String toSimpleDate(LocalDate value) {
return value == null ? null : value.toString();
}
/**
* Convert a List of LocalDate objects to strings.
* @param values The List of LocalDate objects to convert.
* @return The List of converted Strings.
*/
public static List toSimpleDate(List values) {
if (values == null) {
return null;
}
List valuesAsString = new ArrayList<>();
for (LocalDate value : values) {
valuesAsString.add(toSimpleDate(value));
}
return valuesAsString;
}
/**
* Convert a Map of LocalDate objects to strings.
* @param values The Map of LocalDate objects to convert.
* @return The Map of converted Strings.
*/
public static Map toSimpleDate(Map values) {
if (values == null) {
return null;
}
Map valuesAsString = new HashMap<>();
for (Map.Entry value : values.entrySet()) {
valuesAsString.put(value.getKey(), toSimpleDate(value.getValue()));
}
return valuesAsString;
}
/**
* Convert a List of Map of LocalDate objects to strings.
* @param values The List of Map of LocalDate objects to convert.
* @return The list of map of converted Strings.
*/
public static List