Browse Source

Extended Jackson mapping tests.

pull/57/head
Kalle Stenflo 10 years ago
parent
commit
c1a1fbe0e6
  1. 28
      json-path/src/test/java/com/jayway/jsonpath/BaseTest.java
  2. 28
      json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java
  3. 2
      json-path/src/test/java/com/jayway/jsonpath/MapperTest.java

28
json-path/src/test/java/com/jayway/jsonpath/BaseTest.java

@ -2,33 +2,15 @@ package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.Path;
import com.jayway.jsonpath.internal.spi.json.GsonJsonProvider;
import com.jayway.jsonpath.internal.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.internal.spi.mapper.GsonMappingProvider;
import com.jayway.jsonpath.internal.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.internal.token.EvaluationContextImpl;
import com.jayway.jsonpath.internal.token.PredicateContextImpl;
import java.util.HashMap;
public class BaseTest {
/*
static {
Configuration.setDefaults(new Configuration.Defaults() {
@Override
public JsonProvider jsonProvider() {
return new GsonProvider();
}
@Override
public Set<Option> setOptions() {
return EnumSet.noneOf(Option.class);
}
@Override
public ConversionProvider mappingProvider() {
return new DefaultConversionProvider();
}
});
}*/
public static final Configuration GSON_CONFIGURATION = Configuration
.builder()
@ -36,6 +18,12 @@ public class BaseTest {
.jsonProvider(new GsonJsonProvider())
.build();
public static final Configuration JACKSON_CONFIGURATION = Configuration
.builder()
.mappingProvider(new JacksonMappingProvider())
.jsonProvider(new JacksonJsonProvider())
.build();
public static final String JSON_DOCUMENT = "{\n" +
" \"string-property\" : \"string-value\", \n" +
" \"int-max-property\" : " + Integer.MAX_VALUE + ", \n" +

28
json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java

@ -1,19 +1,13 @@
package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.internal.spi.mapper.JacksonMappingProvider;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class JacksonTest {
import java.util.Date;
private static Configuration config = Configuration
.builder()
.mappingProvider(new JacksonMappingProvider())
.jsonProvider(new JacksonJsonProvider())
.build();
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
public class JacksonTest extends BaseTest {
@Test
public void an_object_can_be_mapped_to_pojo() {
@ -25,7 +19,7 @@ public class JacksonTest {
"}";
FooBarBaz fooBarBaz = JsonPath.using(config).parse(json).read("$", FooBarBaz.class);
FooBarBaz fooBarBaz = JsonPath.using(JACKSON_CONFIGURATION).parse(json).read("$", FooBarBaz.class);
assertThat(fooBarBaz.foo).isEqualTo("foo");
assertThat(fooBarBaz.bar).isEqualTo(10L);
@ -39,4 +33,16 @@ public class JacksonTest {
public boolean baz;
}
@Test
public void jackson_converts_dates() {
Date now = new Date();
Object json = singletonMap("date_as_long", now.getTime());
Date date = JsonPath.using(JACKSON_CONFIGURATION).parse(json).read("$['date_as_long']", Date.class);
assertThat(date).isEqualTo(now);
}
}

2
json-path/src/test/java/com/jayway/jsonpath/MapperTest.java

@ -41,4 +41,6 @@ public class MapperTest extends BaseTest {
assertThat(parse("{\"val\": "+now.getTime()+"}").read("val", Date.class)).isEqualTo(now);
}
}

Loading…
Cancel
Save