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

com.oceanprotocol.squid.models.CustomDateDeserializer Maven / Gradle / Ivy

Go to download

Squid facilitate the interaction of java clients with the Ocean Protocol network

There is a newer version: 0.6.2
Show newest version
/*
 * Copyright 2018 Ocean Protocol Foundation
 * SPDX-License-Identifier: Apache-2.0
 */

package com.oceanprotocol.squid.models;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import static com.oceanprotocol.squid.models.AbstractModel.DATE_PATTERN;

public class CustomDateDeserializer extends StdDeserializer {

    private SimpleDateFormat formatter =
            new SimpleDateFormat(DATE_PATTERN);

    public CustomDateDeserializer() {
        this(null);
    }

    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String date = jsonParser.getText();
        try {
            return formatter.parse(date);
        } catch (ParseException e) {
            throw new IOException(e);
        }
    }

    public CustomDateDeserializer(Class vc) {
        super(vc);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy