Skip to content

Commit

Permalink
fix #6: refactors to avoid using JsonPath global configuration
Browse files Browse the repository at this point in the history
ivangsa committed Feb 1, 2024

Verified

This commit was signed with the committer’s verified signature.
ivangsa Iván García Sainz-Aja
1 parent b0d1d25 commit 0596154
Showing 3 changed files with 12 additions and 21 deletions.
27 changes: 6 additions & 21 deletions src/main/java/io/zenwave360/jsonrefparser/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -83,28 +83,13 @@ public static ExtendedJsonContext parse(InputStream inputStream, Object source)
module.addDeserializer(Object.class, jsonDeserializerWithLocations);
mapper.registerModule(module);

Configuration.setDefaults(new Configuration.Defaults() {

private final JsonProvider jsonProvider = new CustomJacksonJsonProvider(mapper);
private final MappingProvider mappingProvider = new JacksonMappingProvider(mapper);

@Override
public JsonProvider jsonProvider() {
return jsonProvider;
}

@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}

@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
});
var jsonPathConfiguration = new Configuration.ConfigurationBuilder()
.jsonProvider(new CustomJacksonJsonProvider(mapper))
.mappingProvider(new JacksonMappingProvider(mapper))
.options(EnumSet.noneOf(Option.class))
.build();
var content = new String(inputStream.readAllBytes());
var parsed = JsonPath.parse(content);
var parsed = JsonPath.parse(content, jsonPathConfiguration);
ExtendedJsonContext.of(parsed, jsonDeserializerWithLocations.getLocations()).toString();
return ExtendedJsonContext.of(parsed, jsonDeserializerWithLocations.getLocations());
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package io.zenwave360.jsonrefparser.resolver;

import io.zenwave360.jsonrefparser.$Ref;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;

public class FileResolver implements Resolver {

private static final Logger log = LoggerFactory.getLogger(FileResolver.class);
@Override
public String resolve($Ref $ref) {
String content = null;
try {
log.info("Resolving file: {}", $ref.getURI());
content = new String(Files.readAllBytes(Paths.get($ref.getURI())));
} catch (NoSuchFileException e) {
throw new MissingResourceException("File not found: " + $ref.getURI(), e);
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ public HttpResolver withAuthentication(AuthenticationValue authenticationValue)
@Override
public String resolve($Ref $ref) {
try {
log.trace("Resolving url: {}", $ref.getURI());
return downloadUrlToString($ref.getURI().toString(), authenticationValues);
} catch (FileNotFoundException e) {
throw new MissingResourceException("File not found: " + $ref.getURI(), e);

0 comments on commit 0596154

Please sign in to comment.