Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
FANNG1 committed May 10, 2024
1 parent 5c9ac8c commit 12f53e0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.shaded.org.awaitility.Awaitility;

@Disabled
@Tag("gravitino-docker-it")
public class DorisTableOperationsIT extends TestDorisAbstractIT {
private static final Type VARCHAR_255 = Types.VarCharType.of(255);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.datastrato.gravitino.rest.RESTResponse;
import com.datastrato.gravitino.rest.RESTUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -692,13 +691,13 @@ public static Builder builder(Map<String, String> properties) {
* URI, request headers, and ObjectMapper.
*/
public static class Builder {

@SuppressWarnings("UnusedVariable")
private final Map<String, String> properties;

private final Map<String, String> baseHeaders = Maps.newHashMap();
private String uri;
private ObjectMapper mapper =
JsonUtils.objectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
private ObjectMapper mapper = JsonUtils.objectMapper();
private AuthDataProvider authDataProvider;
private Runnable beforeConnectHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.datastrato.gravitino.Configs;
import com.datastrato.gravitino.auth.AuthenticatorType;
import com.datastrato.gravitino.config.ConfigEntry;
import com.datastrato.gravitino.json.JsonUtils;
import com.datastrato.gravitino.server.ServerConfig;
import com.datastrato.gravitino.server.authentication.OAuthConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -50,7 +51,7 @@ public ConfigServlet(ServerConfig serverConfig) {
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws IllegalStateException, IOException {
try (PrintWriter writer = res.getWriter()) {
ObjectMapper objectMapper = ObjectMapperProvider.objectMapper();
ObjectMapper objectMapper = JsonUtils.objectMapper();
res.setContentType("application/json;charset=utf-8");
writer.write(objectMapper.writeValueAsString(configs));
} catch (IllegalStateException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,19 @@
*/
package com.datastrato.gravitino.server.web;

import com.datastrato.gravitino.json.JsonUtils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.cfg.EnumFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {
/**
* ObjectMapperHolder is a static inner class that holds the instance of ObjectMapper. This class
* utilizes the Initialization-on-demand holder idiom, which is a lazy-loaded singleton. This
* idiom takes advantage of the fact that inner classes are not loaded until they are referenced.
* It's a thread-safe and efficient way to implement a singleton as the instance is created when
* it's needed at the first time.
*/
private static class ObjectMapperHolder {
private static final ObjectMapper INSTANCE =
JsonMapper.builder()
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(EnumFeature.WRITE_ENUMS_TO_LOWERCASE, true)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build()
.registerModule(new JavaTimeModule());
}

/**
* Get the shared ObjectMapper instance for JSON serialization/deserialization.
*
* @return The ObjectMapper instance.
*/
public static ObjectMapper objectMapper() {
return ObjectMapperHolder.INSTANCE;
}

@Override
public ObjectMapper getContext(Class<?> type) {
ObjectMapper mapper = objectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
ObjectMapper mapper =
JsonUtils.objectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);

return mapper;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.datastrato.gravitino.spark.connector.integration.test.util;
Expand Down

0 comments on commit 12f53e0

Please sign in to comment.