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

com.wultra.app.onboardingserver.provider.zenid.CustomOffsetDateTimeDeserializer Maven / Gradle / Ivy

The newest version!
/*
 * PowerAuth Enrollment Server
 * Copyright (C) 2021 Wultra s.r.o.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package com.wultra.app.onboardingserver.provider.zenid;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;

import java.io.IOException;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * Custom {@link java.time.OffsetDateTime} deserializer which allows also iso date format
 *
 * 

* The ZenID returns simple ISO data on some date elements which are expected to be date-time (e.g. BirthDate) *

*/ class CustomOffsetDateTimeDeserializer extends JsonDeserializer { @Override public OffsetDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException { if (parser.getText() != null && parser.getText().length() == 10) { // yyyy-MM-dd return LocalDate.parse(parser.getText(), DateTimeFormatter.ISO_DATE) .atStartOfDay(ZoneId.of("UTC")) .toOffsetDateTime(); } return InstantDeserializer.OFFSET_DATE_TIME.deserialize(parser, context); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy