Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#575 fix the case when POJO has final fields (#620)
  • Loading branch information
langchain4j committed Feb 9, 2024
1 parent 8421e56 commit b28741e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Expand Up @@ -123,9 +123,7 @@ private static String jsonStructure(Class<?> structured) {
jsonSchema.append("{\n");
for (Field field : structured.getDeclaredFields()) {
String name = field.getName();
if (name.equals("__$hits$__")
|| java.lang.reflect.Modifier.isStatic(field.getModifiers())
|| java.lang.reflect.Modifier.isFinal(field.getModifiers())) {
if (name.equals("__$hits$__") || java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
// Skip coverage instrumentation field.
continue;
}
Expand Down
Expand Up @@ -179,4 +179,28 @@ void outputFormatInstructions_PersonWithNestedObjectArray() {
"}),\n" +
"}");
}

static class PersonWithFinalFields {
private final String firstName;
private final String lastName;
private final LocalDate birthDate;

PersonWithFinalFields(String firstName, String lastName, LocalDate birthDate) {
this.firstName = firstName;
this.lastName = lastName;
this.birthDate = birthDate;
}
}

@Test
void outputFormatInstructions_PersonWithFinalFields() {
String formatInstructions = ServiceOutputParser.outputFormatInstructions(PersonWithFinalFields.class);

assertThat(formatInstructions).isEqualTo(
"\nYou must answer strictly in the following JSON format: {\n" +
"\"firstName\": (type: string),\n" +
"\"lastName\": (type: string),\n" +
"\"birthDate\": (type: date string (2023-12-31)),\n" +
"}");
}
}

0 comments on commit b28741e

Please sign in to comment.