Browse Source

Merge pull request #69 from jochenberger/fix-issue-68

Fix for https://code.google.com/p/json-path/issues/detail?id=68
pull/60/merge
kallestenflo 10 years ago
parent
commit
d2cd96ae1a
  1. 41
      json-path/src/main/java/com/jayway/jsonpath/Configuration.java
  2. 37
      json-path/src/main/java/com/jayway/jsonpath/internal/DefaultsImpl.java

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

@ -14,10 +14,10 @@
*/
package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.DefaultsImpl;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.mapper.JsonSmartMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,26 +38,7 @@ public class Configuration {
private static final Logger logger = LoggerFactory.getLogger(Configuration.class);
private static Defaults DEFAULTS = new Defaults() {
private final MappingProvider mappingProvider = new JsonSmartMappingProvider();
public JsonProvider jsonProvider() {
return new JsonSmartJsonProvider();
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
};
private static Defaults DEFAULTS = null;
/**
* Set Default configuration
@ -67,6 +48,14 @@ public class Configuration {
DEFAULTS = defaults;
}
private static Defaults getEffectiveDefaults(){
if (DEFAULTS == null) {
return DefaultsImpl.INSTANCE;
} else {
return DEFAULTS;
}
}
private final JsonProvider jsonProvider;
private final MappingProvider mappingProvider;
private final Set<Option> options;
@ -186,7 +175,8 @@ public class Configuration {
* @return a new configuration based on defaults
*/
public static Configuration defaultConfiguration() {
return Configuration.builder().jsonProvider(DEFAULTS.jsonProvider()).options(DEFAULTS.options()).build();
Defaults defaults = getEffectiveDefaults();
return Configuration.builder().jsonProvider(defaults.jsonProvider()).options(defaults.options()).build();
}
/**
@ -240,11 +230,12 @@ public class Configuration {
}
public Configuration build() {
Defaults defaults = getEffectiveDefaults();
if (jsonProvider == null) {
jsonProvider = DEFAULTS.jsonProvider();
jsonProvider = defaults.jsonProvider();
}
if(mappingProvider == null){
mappingProvider = DEFAULTS.mappingProvider();
mappingProvider = defaults.mappingProvider();
}
return new Configuration(jsonProvider, mappingProvider, options, evaluationListener);
}

37
json-path/src/main/java/com/jayway/jsonpath/internal/DefaultsImpl.java

@ -0,0 +1,37 @@
package com.jayway.jsonpath.internal;
import java.util.EnumSet;
import java.util.Set;
import com.jayway.jsonpath.Configuration.Defaults;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.mapper.JsonSmartMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
public final class DefaultsImpl implements Defaults {
public static final DefaultsImpl INSTANCE = new DefaultsImpl();
private final MappingProvider mappingProvider = new JsonSmartMappingProvider();
@Override
public JsonProvider jsonProvider() {
return new JsonSmartJsonProvider();
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
private DefaultsImpl() {
};
}
Loading…
Cancel
Save