Skip to content

Commit

Permalink
Merge pull request wiremock#2535 from salehjafarli/bom-in-configjson
Browse files Browse the repository at this point in the history
Parsing config files with BOM character
  • Loading branch information
dieppa authored Jan 18, 2024
2 parents 52a0dcb + 25a1521 commit 3a39fed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ protected ObjectMapper initialValue() {

private Json() {}

public static <T> T read(byte[] stream, Class<T> clazz) throws IOException {
try {
ObjectMapper mapper = getObjectMapper();
return mapper.readValue(stream, clazz);
} catch (JsonProcessingException processingException) {
throw JsonException.fromJackson(processingException);
}
}

public static <T> T read(String json, Class<T> clazz) {
try {
ObjectMapper mapper = getObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
package com.github.tomakehurst.wiremock.standalone;

import static com.github.tomakehurst.wiremock.common.AbstractFileSource.byFileExtension;
import static com.github.tomakehurst.wiremock.common.Exceptions.throwUnchecked;
import static com.github.tomakehurst.wiremock.common.Json.writePrivate;

import com.github.tomakehurst.wiremock.common.*;
import com.github.tomakehurst.wiremock.common.filemaker.FilenameMaker;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import com.github.tomakehurst.wiremock.stubbing.StubMappingCollection;
import com.github.tomakehurst.wiremock.stubbing.StubMappings;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -111,7 +114,7 @@ public void loadMappingsInto(StubMappings stubMappings) {
for (TextFile mappingFile : mappingFiles) {
try {
StubMappingCollection stubCollection =
Json.read(mappingFile.readContentsAsString(), StubMappingCollection.class);
Json.read(mappingFile.readContents(), StubMappingCollection.class);
for (StubMapping mapping : stubCollection.getMappingOrMappings()) {
mapping.setDirty(false);
stubMappings.addMapping(mapping);
Expand All @@ -121,6 +124,8 @@ public void loadMappingsInto(StubMappings stubMappings) {
}
} catch (JsonException e) {
throw new MappingFileException(mappingFile.getPath(), e.getErrors().first().getDetail());
} catch (IOException e) {
throwUnchecked(e);
}
}
}
Expand Down

0 comments on commit 3a39fed

Please sign in to comment.