Skip to content
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
@@ -1,9 +1,15 @@
package org.hypertrace.core.documentstore;

import com.fasterxml.jackson.databind.JsonNode;

public interface Document {

String toJson();

default JsonNode getJsonNode() {
return null;
}

default DocumentType getDocumentType() {
return DocumentType.NESTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public DocumentType getDocumentType() {
return this.documentType;
}

@Override
public JsonNode getJsonNode() {
return node;
}

@Override
public String toJson() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -106,4 +107,16 @@ public void testToStringMethod() throws Exception {
// toString should return the same as toJson
Assertions.assertEquals(document.toJson(), document.toString());
}

@Test
public void testGetJsonMethod() throws IOException {
Map<String, String> data = Map.of("key1", "value1");
JSONDocument document = new JSONDocument(data, DocumentType.FLAT);

JsonNode jsonNode = document.getJsonNode();

Assertions.assertNotNull(jsonNode);
Assertions.assertEquals(mapper.readTree(document.toJson()), jsonNode);
Assertions.assertEquals("value1", jsonNode.get("key1").asText());
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ org-junit-jupiter-junit-jupiter = { module = "org.junit.jupiter:junit-jupiter",
org-mockito-mockito-core = { module = "org.mockito:mockito-core", version.ref = "org-mockito" }
org-mockito-mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter", version.ref = "org-mockito" }
org-mongodb-mongodb-driver-sync = { module = "org.mongodb:mongodb-driver-sync", version = "5.2.0" }
org-postgresql = { module = "org.postgresql:postgresql", version = "42.7.11" }
org-postgresql = { module = "org.postgresql:postgresql", version = "42.7.13" }
org-projectlombok-lombok = { module = "org.projectlombok:lombok", version = "1.18.30" }
org-slf4j-slf4j-api = { module = "org.slf4j:slf4j-api", version = "1.7.36" }
org-testcontainers = { module = "org.testcontainers:testcontainers", version.ref = "org-testcontainers" }
Expand Down
Loading