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
Expand Up @@ -22,6 +22,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -39,7 +40,7 @@ public class CatalogSerializationTest {

@BeforeEach
public void setUp() {
mapper = new ObjectMapper();
mapper = JsonMapper.builder().build();
}

@ParameterizedTest(name = "{0}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
import java.io.IOException;
Expand All @@ -44,8 +45,7 @@ public class OpaSchemaGenerator {
* @throws IOException if schema generation fails
*/
public static String generateSchema() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
ObjectMapper mapper = JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).build();

JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = schemaGen.generateSchema(OpaAuthorizationInput.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.polaris.extension.auth.opa;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import io.smallrye.common.annotation.Identifier;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
Expand Down Expand Up @@ -60,7 +61,7 @@ public OpaPolarisAuthorizerFactory(
this.opaConfig = opaConfig;
this.clock = clock;
this.asyncExec = asyncExec;
this.objectMapper = new ObjectMapper();
this.objectMapper = JsonMapper.builder().build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
Expand Down Expand Up @@ -75,7 +76,7 @@ void testOpaInputJsonFormat() throws Exception {
"http://localhost:" + server.getAddress().getPort() + "/v1/data/polaris/allow");
OpaPolarisAuthorizer authorizer =
new OpaPolarisAuthorizer(
policyUri, HttpClients.createDefault(), new ObjectMapper(), null);
policyUri, HttpClients.createDefault(), JsonMapper.builder().build(), null);

PolarisPrincipal principal =
PolarisPrincipal.of("eve", Map.of("department", "finance"), Set.of("auditor"));
Expand All @@ -95,7 +96,7 @@ void testOpaInputJsonFormat() throws Exception {
secondary));

// Parse and verify JSON structure from captured request
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
assertThat(root.has("input")).as("Root should have 'input' field").isTrue();
var input = root.get("input");
Expand All @@ -120,7 +121,7 @@ void testOpaRequestJsonWithHierarchicalResource() throws Exception {
"http://localhost:" + server.getAddress().getPort() + "/v1/data/polaris/allow");
OpaPolarisAuthorizer authorizer =
new OpaPolarisAuthorizer(
policyUri, HttpClients.createDefault(), new ObjectMapper(), null);
policyUri, HttpClients.createDefault(), JsonMapper.builder().build(), null);

// Set up a realistic principal
PolarisPrincipal principal =
Expand Down Expand Up @@ -185,7 +186,7 @@ void testOpaRequestJsonWithHierarchicalResource() throws Exception {
null));

// Parse and verify the complete JSON structure
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);

// Verify top-level structure
Expand Down Expand Up @@ -273,7 +274,7 @@ void testOpaRequestJsonWithMultiLevelNamespace() throws Exception {
"http://localhost:" + server.getAddress().getPort() + "/v1/data/polaris/allow");
OpaPolarisAuthorizer authorizer =
new OpaPolarisAuthorizer(
policyUri, HttpClients.createDefault(), new ObjectMapper(), null);
policyUri, HttpClients.createDefault(), JsonMapper.builder().build(), null);

// Set up a realistic principal
PolarisPrincipal principal =
Expand Down Expand Up @@ -350,7 +351,7 @@ void testOpaRequestJsonWithMultiLevelNamespace() throws Exception {
null));

// Parse and verify the complete JSON structure
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);

// Verify top-level structure
Expand Down Expand Up @@ -437,7 +438,7 @@ void testAuthorizeOrThrowWithEmptyTargetsAndSecondaries() throws Exception {
"http://localhost:" + server.getAddress().getPort() + "/v1/data/polaris/allow");
OpaPolarisAuthorizer authorizer =
new OpaPolarisAuthorizer(
policyUri, HttpClients.createDefault(), new ObjectMapper(), null);
policyUri, HttpClients.createDefault(), JsonMapper.builder().build(), null);

PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("admin"));

Expand Down Expand Up @@ -483,7 +484,7 @@ public void testCreateWithHttpsAndBearerToken() {
URI policyUri = URI.create("http://opa.example.com:8181/v1/data/polaris/allow");
OpaPolarisAuthorizer authorizer =
new OpaPolarisAuthorizer(
policyUri, HttpClients.createDefault(), new ObjectMapper(), tokenProvider);
policyUri, HttpClients.createDefault(), JsonMapper.builder().build(), tokenProvider);

assertThat(authorizer).isNotNull();
}
Expand All @@ -499,7 +500,10 @@ public void testBearerTokenIsAddedToHttpRequest() {
BearerTokenProvider tokenProvider = new StaticBearerTokenProvider("test-bearer-token");
OpaPolarisAuthorizer authorizer =
new OpaPolarisAuthorizer(
policyUri, mock(CloseableHttpClient.class), new ObjectMapper(), tokenProvider) {
policyUri,
mock(CloseableHttpClient.class),
JsonMapper.builder().build(),
tokenProvider) {
@Override
<T> T httpClientExecute(
ClassicHttpRequest request, HttpClientResponseHandler<? extends T> responseHandler)
Expand Down Expand Up @@ -541,7 +545,10 @@ public void testBearerTokenFromBearerTokenProvider() {
// Create authorizer with the token provider instead of static token
OpaPolarisAuthorizer authorizer =
new OpaPolarisAuthorizer(
policyUri, mock(CloseableHttpClient.class), new ObjectMapper(), tokenProvider) {
policyUri,
mock(CloseableHttpClient.class),
JsonMapper.builder().build(),
tokenProvider) {
@Override
<T> T httpClientExecute(
ClassicHttpRequest request, HttpClientResponseHandler<? extends T> responseHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -401,7 +402,7 @@ public void testJwtWithoutExpirationClaim() throws IOException {
/** Helper method to create a JWT with a specific expiration time. */
private String createJwtWithExpiration(Instant expiration) {
try {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();

// Create header
Map<String, Object> header = new HashMap<>();
Expand Down Expand Up @@ -438,7 +439,7 @@ private String createJwtWithExpiration(Instant expiration) {
/** Helper method to create a JWT without an expiration claim. */
private String createJwtWithoutExpiration() {
try {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();

// Create header
Map<String, Object> header = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.json.JsonMapper;
import jakarta.ws.rs.client.Client;
import java.net.URI;
import java.util.Map;
Expand Down Expand Up @@ -64,7 +65,7 @@ public static PolarisClient polarisClient(PolarisApiEndpoints endpoints) {
* ObjectMapper} if the make custom {@link PolarisServerManager#createClient() clients}.
*/
public static ObjectMapper buildObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setPropertyNamingStrategy(new PropertyNamingStrategies.KebabCaseStrategy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.auth0.jwt.algorithms.Algorithm;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;
import jakarta.ws.rs.client.Entity;
Expand Down Expand Up @@ -159,7 +160,7 @@ public void testCatalogSerializing() throws IOException {
.build())
.build();

ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
String json = mapper.writeValueAsString(catalog);
System.out.println(json);
Catalog deserialized = mapper.readValue(json, Catalog.class);
Expand Down Expand Up @@ -334,7 +335,7 @@ public void testCreateCatalogWithNullBaseLocation() {
.setStorageType(StorageConfigInfo.StorageTypeEnum.S3)
.setAllowedLocations(List.of("s3://my-old-bucket/path/to/data"))
.build();
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode storageConfig = mapper.valueToTree(awsConfigModel);
ObjectNode catalogNode = mapper.createObjectNode();
catalogNode.set("storageConfigInfo", storageConfig);
Expand All @@ -359,7 +360,7 @@ public void testCreateCatalogWithoutProperties() {
.setStorageType(StorageConfigInfo.StorageTypeEnum.S3)
.setAllowedLocations(List.of("s3://my-old-bucket/path/to/data"))
.build();
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode storageConfig = mapper.valueToTree(awsConfigModel);
ObjectNode catalogNode = mapper.createObjectNode();
catalogNode.set("storageConfigInfo", storageConfig);
Expand Down Expand Up @@ -513,7 +514,7 @@ public void testCreateCatalogWithoutDefaultLocation() {
.setStorageType(StorageConfigInfo.StorageTypeEnum.S3)
.setAllowedLocations(List.of("s3://my-old-bucket/path/to/data"))
.build();
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode storageConfig = mapper.valueToTree(awsConfigModel);
ObjectNode catalogNode = mapper.createObjectNode();
catalogNode.set("storageConfigInfo", storageConfig);
Expand All @@ -534,7 +535,7 @@ public void testCreateCatalogWithoutDefaultLocation() {
@Test
public void serialization() {
CatalogProperties properties = new CatalogProperties("s3://my-bucket/path/to/data");
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = JsonMapper.builder().build();
CatalogProperties translated = mapper.convertValue(properties, CatalogProperties.class);
assertThat(translated.toMap())
.containsEntry("default-base-location", "s3://my-bucket/path/to/data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
*/
package org.apache.polaris.persistence.nosql.authz.impl;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import java.util.stream.Stream;
import org.apache.polaris.persistence.nosql.authz.api.AclEntry;
import org.apache.polaris.persistence.nosql.authz.api.Privilege;
Expand All @@ -39,7 +43,12 @@ public class TestAclEntryImpl {

@BeforeAll
static void setUp() {
mapper = new ObjectMapper().findAndRegisterModules();
mapper =
JsonMapper.builder()
.findAndAddModules()
.disable(FAIL_ON_UNKNOWN_PROPERTIES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These features weren't present in the previous code, why do we need to add those now? There are many other occurrences of this in the PR, so I suppose there has to be some good reason to do so 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes.
So in Jackson 2, FAIL_ON_UNKNOWN_PROPERTIES defaults to true, in Jackson 3 it defaults to false.
DEFAULT_VIEW_INCLUSION defaults to true in Jackson 2, but in Jackson 3 it defaults to false.
TL;DR a no-op-change for Jackson 2, but a required change for Jackson 3, to already account for these breaking changes.

.enable(DEFAULT_VIEW_INCLUSION)
.build();
privileges =
new PrivilegesImpl(Stream.of(new PrivilegesTestProvider()), new PrivilegesTestRepository());
JacksonPrivilegesModule.CDIResolver.setResolver(x -> privileges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.polaris.persistence.nosql.authz.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import java.util.stream.Stream;
import org.apache.polaris.persistence.nosql.authz.api.Acl;
import org.apache.polaris.persistence.nosql.authz.api.Privilege;
Expand All @@ -41,7 +42,7 @@ public class TestAclImpl {

@BeforeAll
static void setUp() {
mapper = new ObjectMapper().findAndRegisterModules();
mapper = JsonMapper.builder().findAndAddModules().build();
privileges =
new PrivilegesImpl(Stream.of(new PrivilegesTestProvider()), new PrivilegesTestRepository());
JacksonPrivilegesModule.CDIResolver.setResolver(x -> privileges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
*/
package org.apache.polaris.persistence.nosql.authz.impl;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION;
import static java.util.Collections.singleton;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.ArrayList;
import java.util.Set;
Expand Down Expand Up @@ -54,7 +57,12 @@ static final class StorageView {}

@BeforeAll
static void setUp() {
mapper = new ObjectMapper().findAndRegisterModules();
mapper =
JsonMapper.builder()
.findAndAddModules()
.disable(FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DEFAULT_VIEW_INCLUSION)
.build();
privileges =
new PrivilegesImpl(Stream.of(new PrivilegesTestProvider()), new PrivilegesTestRepository());
JacksonPrivilegesModule.CDIResolver.setResolver(x -> privileges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.jupiter.params.provider.Arguments.arguments;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.dataformat.smile.databind.SmileMapper;
import java.nio.ByteBuffer;
import java.util.Arrays;
Expand All @@ -47,8 +48,8 @@ public class TestPersistId {

@BeforeEach
protected void setUp() {
mapper = new ObjectMapper();
smile = new SmileMapper();
mapper = JsonMapper.builder().build();
smile = SmileMapper.builder().build();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/
package org.apache.polaris.persistence.nosql.api.obj;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION;
import static org.apache.polaris.persistence.nosql.api.obj.ObjSerializationHelper.contextualReader;
import static org.apache.polaris.persistence.nosql.api.obj.ObjTypes.objTypeById;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;
Expand All @@ -41,7 +43,12 @@ public class TestGenericObj {
@ParameterizedTest
@MethodSource
public void genericObj(ObjType realType, long id, Obj realObj) throws Exception {
var mapper = new ObjectMapper().findAndRegisterModules();
var mapper =
JsonMapper.builder()
.findAndAddModules()
.disable(FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DEFAULT_VIEW_INCLUSION)
.build();
// Use some view to exclude the type,id,createdAtMicros,versionToken attributes from being
// serialized by Jackson.
var writerAllAttributes = mapper.writer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.apache.polaris.persistence.nosql.api.obj.ObjRef.objRef;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.dataformat.smile.databind.SmileMapper;
import java.nio.ByteBuffer;
import java.util.Base64;
Expand All @@ -46,8 +47,8 @@ public class TestObjRef {

@BeforeEach
protected void setUp() {
mapper = new ObjectMapper();
smile = new SmileMapper();
mapper = JsonMapper.builder().build();
smile = SmileMapper.builder().build();
}

@Test
Expand Down
Loading