Skip to content

Commit

Permalink
Merge pull request #651 from humcqc/main
Browse files Browse the repository at this point in the history
Ollama Illegal unquoted character
  • Loading branch information
geoand authored Jun 3, 2024
2 parents feee852 + 67e034c commit 8526daf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ void toInputStreamWorksForList() throws IOException {
}
}

@Test
void illegalUnquotedChar() {
String text = """
Here is the options:
- option 1
- option 2
""";
Response expectedResponse = new Response(text);

String json = "{ " +
"\"answer\" : \"" + text + "\"" +
"}";
Response actualResponse = Json.fromJson(json, Response.class);

assertThat(actualResponse.getAnswer()).isEqualTo(expectedResponse.getAnswer());
}

private static class Response {
private final String answer;

@JsonCreator
public Response(String answer) {
this.answer = answer;
}

public String getAnswer() {
return this.answer;
}
}

private static class TestObject {
private final String name;
private final LocalDate date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
Expand Down Expand Up @@ -71,7 +72,8 @@ public static class ObjectMapperHolder {
MAPPER = Arc.container().instance(ObjectMapper.class).get()
.copy()
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
WRITER = MAPPER.writerWithDefaultPrettyPrinter();
}
}
Expand All @@ -81,7 +83,8 @@ public static class SnakeCaseObjectMapperHolder {
.copy()
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.enable(SerializationFeature.INDENT_OUTPUT);
.enable(SerializationFeature.INDENT_OUTPUT)
.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
}

}

0 comments on commit 8526daf

Please sign in to comment.