fix(ocr): handle unknown NDJSON fields with @JsonIgnoreProperties
Added @JsonIgnoreProperties(ignoreUnknown = true) to OcrBlockResult so new fields from the Python OCR service don't crash the Java parser, while keeping FAIL_ON_UNKNOWN_PROPERTIES strict globally. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
package org.raddatz.familienarchiv.service;
|
package org.raddatz.familienarchiv.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public record OcrBlockResult(
|
public record OcrBlockResult(
|
||||||
int pageNumber,
|
int pageNumber,
|
||||||
double x,
|
double x,
|
||||||
|
|||||||
@@ -98,6 +98,23 @@ class RestClientOcrClientStreamTest {
|
|||||||
assertThat(events).hasSize(2);
|
assertThat(events).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parseNdjsonStream_handlesUnknownFieldsInBlocks() {
|
||||||
|
String ndjson = """
|
||||||
|
{"type":"start","totalPages":1}
|
||||||
|
{"type":"page","pageNumber":0,"blocks":[{"pageNumber":0,"x":0.1,"y":0.2,"width":0.8,"height":0.1,"polygon":null,"text":"Line 1","confidence":0.95,"newFutureField":"ignored"}]}
|
||||||
|
{"type":"done","totalBlocks":1,"skippedPages":0}
|
||||||
|
""";
|
||||||
|
InputStream stream = new ByteArrayInputStream(ndjson.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
List<OcrStreamEvent> events = new ArrayList<>();
|
||||||
|
RestClientOcrClient.parseNdjsonStream(stream, events::add);
|
||||||
|
|
||||||
|
assertThat(events).hasSize(3);
|
||||||
|
var page = (OcrStreamEvent.Page) events.get(1);
|
||||||
|
assertThat(page.blocks().get(0).text()).isEqualTo("Line 1");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void parseNdjsonStream_parsesPageWithPolygon() {
|
void parseNdjsonStream_parsesPageWithPolygon() {
|
||||||
String ndjson = """
|
String ndjson = """
|
||||||
|
|||||||
Reference in New Issue
Block a user