Search in sources :

Example 1 with StdDateFormat

use of com.fasterxml.jackson.databind.util.StdDateFormat in project jackson-databind by FasterXML.

the class TestStdDateFormat method testLenientParsing.

public void testLenientParsing() throws Exception {
    StdDateFormat f = StdDateFormat.instance.clone();
    f.setLenient(false);
    // first, legal dates are... legal
    Date dt = f.parse("2015-11-30");
    assertNotNull(dt);
    // but as importantly, when not lenient, do not allow
    try {
        f.parse("2015-11-32");
        fail("Should not pass");
    } catch (ParseException e) {
        verifyException(e, "can not parse date");
    }
    // ... yet, with lenient, do allow
    f.setLenient(true);
    dt = f.parse("2015-11-32");
    assertNotNull(dt);
}
Also used : StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat) ParseException(java.text.ParseException)

Example 2 with StdDateFormat

use of com.fasterxml.jackson.databind.util.StdDateFormat in project jackson-databind by FasterXML.

the class TestStdDateFormat method testLenientDefaults.

// [databind#803]
public void testLenientDefaults() throws Exception {
    StdDateFormat f = StdDateFormat.instance;
    // default should be lenient
    assertTrue(f.isLenient());
    StdDateFormat f2 = f.clone();
    assertTrue(f2.isLenient());
    f2.setLenient(false);
    assertFalse(f2.isLenient());
    f2.setLenient(true);
    assertTrue(f2.isLenient());
    // and for testing, finally, leave as non-lenient
    f2.setLenient(false);
    assertFalse(f2.isLenient());
    StdDateFormat f3 = f2.clone();
    assertFalse(f3.isLenient());
}
Also used : StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat)

Aggregations

StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)2 ParseException (java.text.ParseException)1