Example usage for com.fasterxml.jackson.databind.util StdDateFormat parse

List of usage examples for com.fasterxml.jackson.databind.util StdDateFormat parse

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.util StdDateFormat parse.

Prototype

public Date parse(String paramString) 

Source Link

Usage

From source file:org.jmingo.mapping.convert.mongo.type.deserialize.MongoDateDeserializer.java

/**
 * {@inheritDoc}/*  w  ww.jav a2  s.c om*/
 */
@Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode tree = jp.readValueAsTree();
    if (tree.isPojo()) {
        POJONode pojoNode = (POJONode) tree;
        Object pojo = pojoNode.getPojo();

        if (pojo instanceof Date) {
            return (Date) pojoNode.getPojo();
        } else {
            throw new RuntimeException("unsupported date type, expected: " + Date.class.getName());
        }
    }
    String stringDate = tree.asText();
    StdDateFormat stdDateFormat = new StdDateFormat();
    try {
        return stdDateFormat.parse(stringDate);
    } catch (ParseException e) {
        throw Throwables.propagate(e);
    }

}