Example usage for com.fasterxml.jackson.databind DeserializationContext getTimeZone

List of usage examples for com.fasterxml.jackson.databind DeserializationContext getTimeZone

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind DeserializationContext getTimeZone.

Prototype

public TimeZone getTimeZone() 

Source Link

Usage

From source file:de.taimos.dvalin.interconnect.model.DateTimeKeyDeserializer.java

@Override
protected Object _parse(String key, DeserializationContext ctxt) throws Exception {
    if (key.length() == 0) { // [JACKSON-360]
        return null;
    }//from w w  w .  j  a va2 s .  com
    return new DateTime(key, DateTimeZone.forTimeZone(ctxt.getTimeZone()));
}

From source file:de.taimos.dvalin.interconnect.model.DateTimeDeserializerWithTZ.java

@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonToken t = jp.getCurrentToken();/*  w  w  w . j av  a  2 s  .com*/
    if (t == JsonToken.VALUE_NUMBER_INT) {
        return new DateTime(jp.getLongValue(), DateTimeZone.forTimeZone(ctxt.getTimeZone()));
    }
    if (t == JsonToken.VALUE_STRING) {
        String str = jp.getText().trim();
        if (str.length() == 0) { // [JACKSON-360]
            return null;
        }
        // catch serialized time zones
        if ((str.charAt(str.length() - 6) == '+') || (str.charAt(str.length() - 1) == 'Z')
                || (str.charAt(str.length() - 6) == '-')) {
            return new DateTime(str);
        }
        return new DateTime(str, DateTimeZone.forTimeZone(ctxt.getTimeZone()));
    }
    ctxt.handleUnexpectedToken(this.handledType(), jp);
    // never reached
    return null;
}