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

com.owlike.genson.ext.javadatetime.LocalDateConverter Maven / Gradle / Ivy

package com.owlike.genson.ext.javadatetime;

import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalField;
import java.util.LinkedHashMap;

/**
 * Converter for values of type {@link LocalDate}
 */
public class LocalDateConverter extends BaseTemporalAccessorConverter {
	LocalDateConverter(DateTimeConverterOptions options) {
		super(options, new LocalDateTimestampHandler(options), LocalDate::from);
	}

	private static class LocalDateTimestampHandler extends TimestampHandler {
		private static final LinkedHashMap LOCAL_DATE_TEMPORAL_FIELDS = new LinkedHashMap<>();
		static{
			LOCAL_DATE_TEMPORAL_FIELDS.put("year", ChronoField.YEAR);
			LOCAL_DATE_TEMPORAL_FIELDS.put("month", ChronoField.MONTH_OF_YEAR);
			LOCAL_DATE_TEMPORAL_FIELDS.put("day", ChronoField.DAY_OF_MONTH);
		}

		private LocalDateTimestampHandler(DateTimeConverterOptions options) {
			super(LocalDate::toEpochDay, LocalDate::ofEpochDay, LocalDate::toEpochDay, LocalDate::ofEpochDay,
					LOCAL_DATE_TEMPORAL_FIELDS, LocalDate::now);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy