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

com.vaadin.server.communication.DateSerializer Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */
package com.vaadin.server.communication;

import java.lang.reflect.Type;
import java.util.Date;

import com.vaadin.ui.ConnectorTracker;

import elemental.json.Json;
import elemental.json.JsonValue;

/**
 * Server side serializer/deserializer for java.util.Date.
 *
 * @since 7.2
 * @author Vaadin Ltd
 */
public class DateSerializer implements JSONSerializer {

    @Override
    public Date deserialize(Type type, JsonValue jsonValue,
            ConnectorTracker connectorTracker) {
        return new Date((long) jsonValue.asNumber());
    }

    @Override
    public JsonValue serialize(Date value, ConnectorTracker connectorTracker) {
        return Json.create(value.getTime());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy