Avoid using Java 8 ZoneId class

Issue: SPR-12594
This commit is contained in:
Sebastien Deleuze 2015-01-20 15:24:55 +01:00
parent b89e62e5f6
commit bf7a9754d5
3 changed files with 15 additions and 13 deletions

View File

@ -18,7 +18,6 @@ package org.springframework.http.converter.json;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@ -168,7 +167,7 @@ public class Jackson2ObjectMapperBuilder {
* @since 4.1.5
*/
public Jackson2ObjectMapperBuilder timeZone(String zoneId) {
this.timeZone = TimeZone.getTimeZone(ZoneId.of(zoneId));
this.timeZone = TimeZone.getTimeZone(zoneId);
return this;
}

View File

@ -17,8 +17,6 @@
package org.springframework.http.converter.json;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.zone.ZoneRulesException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@ -179,7 +177,7 @@ public class Jackson2ObjectMapperBuilderTests {
@Test
public void timeZoneSetter() {
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("Europe/Paris"));
TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(timeZone).build();
assertEquals(timeZone, objectMapper.getSerializationConfig().getTimeZone());
assertEquals(timeZone, objectMapper.getDeserializationConfig().getTimeZone());
@ -189,15 +187,18 @@ public class Jackson2ObjectMapperBuilderTests {
public void timeZoneStringSetter() {
String zoneId = "Europe/Paris";
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build();
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of(zoneId));
TimeZone timeZone = TimeZone.getTimeZone(zoneId);
assertEquals(timeZone, objectMapper.getSerializationConfig().getTimeZone());
assertEquals(timeZone, objectMapper.getDeserializationConfig().getTimeZone());
}
@Test(expected = ZoneRulesException.class)
@Test
public void wrongTimeZoneStringSetter() {
String zoneId = "foo";
Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().timeZone(zoneId).build();
TimeZone timeZone = TimeZone.getTimeZone("GMT");
assertEquals(timeZone, objectMapper.getSerializationConfig().getTimeZone());
assertEquals(timeZone, objectMapper.getDeserializationConfig().getTimeZone());
}
@Test

View File

@ -17,8 +17,6 @@
package org.springframework.http.converter.json;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.zone.ZoneRulesException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@ -176,7 +174,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
@Test
public void timeZoneSetter() {
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("Europe/Paris"));
TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
this.factory.setTimeZone(timeZone);
this.factory.afterPropertiesSet();
@ -192,17 +190,21 @@ public class Jackson2ObjectMapperFactoryBeanTests {
this.factory.setTimeZone(zoneId);
this.factory.afterPropertiesSet();
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of(zoneId));
TimeZone timeZone = TimeZone.getTimeZone(zoneId);
assertEquals(timeZone, this.factory.getObject().getSerializationConfig().getTimeZone());
assertEquals(timeZone, this.factory.getObject().getDeserializationConfig().getTimeZone());
}
@Test(expected = ZoneRulesException.class)
@Test
public void wrongTimeZoneStringSetter() {
String zoneId = "foo";
this.factory.setTimeZone(zoneId);
this.factory.afterPropertiesSet();
TimeZone timeZone = TimeZone.getTimeZone("GMT");
assertEquals(timeZone, this.factory.getObject().getSerializationConfig().getTimeZone());
assertEquals(timeZone, this.factory.getObject().getDeserializationConfig().getTimeZone());
}
@Test