Browse Source

Fixed failing test.

pull/56/head
Kalle Stenflo 10 years ago
parent
commit
2d01aa630b
  1. 21
      json-path/src/main/java/com/jayway/jsonpath/Configuration.java
  2. 107
      json-path/src/test/java/com/jayway/jsonpath/ObjectMapperTest.java

21
json-path/src/main/java/com/jayway/jsonpath/Configuration.java

@ -14,10 +14,10 @@
*/ */
package com.jayway.jsonpath; package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.spi.mapper.DefaultMappingProvider;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider; import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider; import com.jayway.jsonpath.internal.spi.mapper.DefaultMappingProvider;
import com.jayway.jsonpath.spi.json.JsonProvider; import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
@ -47,6 +47,10 @@ public class Configuration {
} }
}; };
/**
* Set Default configuration
* @param defaults default configuration settings
*/
public static synchronized void setDefaults(Defaults defaults){ public static synchronized void setDefaults(Defaults defaults){
DEFAULTS = defaults; DEFAULTS = defaults;
} }
@ -147,11 +151,22 @@ public class Configuration {
} }
public interface Defaults { public interface Defaults {
/**
* Returns the default {@link com.jayway.jsonpath.spi.json.JsonProvider}
* @return default json provider
*/
JsonProvider jsonProvider(); JsonProvider jsonProvider();
/**
* Returns default options
* @return options
*/
Set<Option> options(); Set<Option> options();
/**
*
* @return
*/
MappingProvider mappingProvider(); MappingProvider mappingProvider();
} }

107
json-path/src/test/java/com/jayway/jsonpath/ObjectMapperTest.java

@ -1,107 +0,0 @@
package com.jayway.jsonpath;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.minidev.json.mapper.Mapper;
import org.junit.Test;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class ObjectMapperTest {
ObjectMapper objectMapper = new ObjectMapper();
@Test
public void mapping() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", "MAP FOO");
map.put("bar", Long.MAX_VALUE);
Baz baz = new Baz();
baz.setFlurb("FLURB");
FooBar fooBar = new FooBar();
fooBar.setFoo("OBJ FOO");
fooBar.setBar(Long.MIN_VALUE);
fooBar.setBaz(baz);
Map mappedMap = objectMapper.convertValue(fooBar, Map.class);
System.out.println(mappedMap);
/*
FooBar foobar = objectMapper.convertValue(map, FooBar.class);
Integer integer = objectMapper.convertValue(1L, Integer.class);
Integer integer2 = objectMapper.convertValue(1D, Integer.class);
String date = objectMapper.convertValue(new Date(System.currentTimeMillis()), String.class);
*/
Mapper mapper = new Mapper();
Long convert = mapper.getMapper(Long.class).convert(1D);
System.out.println(convert);
}
public static class FooBar {
private String foo;
private Long bar;
private Baz baz;
public FooBar() {
}
public Baz getBaz() {
return baz;
}
public void setBaz(Baz baz) {
this.baz = baz;
}
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
public Long getBar() {
return bar;
}
public void setBar(Long bar) {
this.bar = bar;
}
}
public static class Baz {
private String flurb;
public Baz() {
}
public String getFlurb() {
return flurb;
}
public void setFlurb(String flurb) {
this.flurb = flurb;
}
}
}
Loading…
Cancel
Save