Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ollama Illegal unquoted character #651

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
humcqc marked this conversation as resolved.
Show resolved Hide resolved
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);
}

}
Loading