Skip to content

Commit

Permalink
Fix 3.0 tests wrt new escape-by-default slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 12, 2024
1 parent 9bd9741 commit 11ecd87
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/test/java/tools/jackson/datatype/joda/DateTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import tools.jackson.core.json.JsonWriteFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationFeature;

Expand Down Expand Up @@ -79,6 +81,7 @@ private static interface TypeInfoMixIn {
private final ObjectMapper MAPPER = mapperWithModule();

private final static ObjectMapper STRING_MAPPER = mapperWithModuleBuilder()
.disable(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.build();

Expand Down
15 changes: 7 additions & 8 deletions src/test/java/tools/jackson/datatype/joda/JodaTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.CoercionAction;
import tools.jackson.databind.cfg.CoercionInputShape;
import tools.jackson.databind.cfg.MapperBuilder;
import tools.jackson.databind.json.JsonMapper;

import junit.framework.TestCase;
Expand Down Expand Up @@ -59,36 +58,36 @@ protected static interface MixinForPolymorphism {
/**********************************************************************
*/

protected static MapperBuilder<?,?> mapperWithModuleBuilder() {
protected static JsonMapper.Builder mapperWithModuleBuilder() {
return JsonMapper.builder()
.addModule(new JodaModule());
}

protected static MapperBuilder<?,?> jodaMapperBuilder(DateFormat df) {
protected static JsonMapper.Builder jodaMapperBuilder(DateFormat df) {
return mapperWithModuleBuilder()
.defaultDateFormat(df);
}

protected static MapperBuilder<?,?> jodaMapperBuilder(TimeZone tz) {
protected static JsonMapper.Builder jodaMapperBuilder(TimeZone tz) {
return mapperWithModuleBuilder()
.defaultTimeZone(tz);
}

protected static ObjectMapper mapperWithModule() {
protected static JsonMapper mapperWithModule() {
return mapperWithModuleBuilder().build();
}

protected static ObjectMapper mapperWithModule(DateFormat df) {
protected static JsonMapper mapperWithModule(DateFormat df) {
return jodaMapperBuilder(df)
.build();
}

protected static ObjectMapper mapperWithModule(TimeZone tz) {
protected static JsonMapper mapperWithModule(TimeZone tz) {
return jodaMapperBuilder(tz)
.build();
}

protected static ObjectMapper mapperWithFailFromEmptyString() {
protected static JsonMapper mapperWithFailFromEmptyString() {
return mapperWithModuleBuilder()
.withCoercionConfigDefaults(cfg ->
cfg.setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail)
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/tools/jackson/datatype/joda/TimeZoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.joda.time.DateTimeZone;

import com.fasterxml.jackson.annotation.JsonTypeInfo;

import tools.jackson.core.json.JsonWriteFeature;

import tools.jackson.databind.*;

// for [datatype-joda#44]
Expand Down Expand Up @@ -37,7 +40,9 @@ private static interface TypeInfoMixIn {
/**********************************************************
*/

private final ObjectMapper MAPPER = mapperWithModule();
private final ObjectMapper MAPPER = mapperWithModuleBuilder()
.disable(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.build();

public void testSimple() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.joda.time.DateTime;
import org.joda.time.Instant;

import tools.jackson.core.json.JsonWriteFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.datatype.joda.JodaTestBase;
Expand Down Expand Up @@ -32,6 +33,7 @@ public void testCustomFormatInstantSer() throws Exception
{
final String json = MAPPER.writer()
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.without(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.writeValueAsString(new FormattedInstant(new Instant(0L)));
assertEquals(aposToQuotes(
"{'value':'01/01/1970 00_00_00_000'}"), json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import tools.jackson.core.json.JsonWriteFeature;
import tools.jackson.databind.*;
import tools.jackson.datatype.joda.JodaTestBase;

Expand All @@ -31,6 +33,7 @@ static class FormattedInterval
private final ObjectMapper MAPPER = mapperWithModuleBuilder()
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.disable(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.build();

private final ObjectWriter WRITER = MAPPER.writer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import tools.jackson.core.json.JsonWriteFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectWriter;
import tools.jackson.databind.SerializationFeature;
Expand Down Expand Up @@ -37,6 +38,7 @@ public T getContents() {
private final ObjectMapper MAPPER = mapperWithModuleBuilder()
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.disable(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.build();

private final ObjectWriter WRITER = MAPPER.writer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.joda.time.DateTimeZone;

import com.fasterxml.jackson.annotation.JsonFormat;

import tools.jackson.core.json.JsonWriteFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.datatype.joda.JodaTestBase;

Expand All @@ -24,7 +26,9 @@ public DummyClassWithDate(DateTime date) {

public void testJacksonAnnotatedPOJOWithDateWithTimezoneToJson() throws Exception
{
ObjectMapper mapper = mapperWithModule();
ObjectMapper mapper = mapperWithModuleBuilder()
.disable(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.build();
String ZONE_ID = "Asia/Krasnoyarsk";

DummyClassWithDate input = new DummyClassWithDate(new DateTime(2015, 11, 23, 22, 06, 39,
Expand Down

0 comments on commit 11ecd87

Please sign in to comment.