elasticsearch-java
elasticsearch-java copied to clipboard
deserializing co.elastic.clients.elasticsearch.core.search.Hit: jakarta.json.JsonException: Jackson exception (JSON path: hits.hits[0]._source) (line no=1, column no=250, offset=-1)
Java API client version
8.6.0
Java version
11
Elasticsearch Version
8.6.0
Problem description
List<NoteDoc> result = new ArrayList<>();
MatchAllQuery query = QueryBuilders.matchAll().build();
SearchRequest request = new SearchRequest.Builder()
.index(ES_NOTE_INDEX)
.query(query._toQuery())
.build();
try {
SearchResponse<NoteDoc> search = elasticsearchClient.search(request, NoteDoc.class);
for (Hit<NoteDoc> hit : search.hits().hits()) {
log.info("Note: {}",hit.source());
result.add(hit.source());
}
return RestResponse.success(result);
} catch (IOException e) {
log.error(e.getMessage());
TravelNoteException.cast(e.getMessage());
}
Java entity classes need to add constructors, and Jackson deserialization needs to go through the constructor of entity classes.
I guess "entity class" is NoteDoc
? This seems like a problem in the configuration of Jackson. We need more details to confirm that.
Can you test the deserialiation of JSON data in the NoteDoc
class with Jackson independently of the Elasticsearch client ?
Hello, is this still an issue? I'll close this otherwise.