-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(json-converter): fix iceberg json converter
- Loading branch information
1 parent
965633a
commit a559a02
Showing
6 changed files
with
114 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...log/src/main/java/io/datahubproject/iceberg/catalog/rest/common/IcebergJsonConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.datahubproject.iceberg.catalog.rest.common; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.lang.reflect.GenericArrayType; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.lang.reflect.WildcardType; | ||
import javax.annotation.Nonnull; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
|
||
public class IcebergJsonConverter extends MappingJackson2HttpMessageConverter { | ||
private static final String ICEBERG_PACKAGE_PREFIX = "org.apache.iceberg."; | ||
|
||
public IcebergJsonConverter(ObjectMapper objectMapper) { | ||
super(objectMapper); | ||
} | ||
|
||
@Override | ||
protected boolean supports(@Nonnull Class<?> clazz) { | ||
return isClassInPackage(clazz); | ||
} | ||
|
||
@Override | ||
public boolean canRead(@Nonnull Type type, Class<?> contextClass, MediaType mediaType) { | ||
return hasTypeInPackage(type) && super.canRead(type, contextClass, mediaType); | ||
} | ||
|
||
@Override | ||
public boolean canWrite(@Nonnull Class<?> clazz, MediaType mediaType) { | ||
return isClassInPackage(clazz) && super.canWrite(clazz, mediaType); | ||
} | ||
|
||
private boolean hasTypeInPackage(Type type) { | ||
if (type instanceof Class<?>) { | ||
return isClassInPackage((Class<?>) type); | ||
} | ||
|
||
if (type instanceof ParameterizedType) { | ||
ParameterizedType paramType = (ParameterizedType) type; | ||
|
||
// Check raw type | ||
Type rawType = paramType.getRawType(); | ||
if (rawType instanceof Class<?> && isClassInPackage((Class<?>) rawType)) { | ||
return true; | ||
} | ||
|
||
// Recursively check type arguments | ||
for (Type typeArg : paramType.getActualTypeArguments()) { | ||
if (hasTypeInPackage(typeArg)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
if (type instanceof WildcardType) { | ||
WildcardType wildcardType = (WildcardType) type; | ||
// Check upper bounds | ||
for (Type bound : wildcardType.getUpperBounds()) { | ||
if (hasTypeInPackage(bound)) { | ||
return true; | ||
} | ||
} | ||
// Check lower bounds | ||
for (Type bound : wildcardType.getLowerBounds()) { | ||
if (hasTypeInPackage(bound)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
if (type instanceof GenericArrayType) { | ||
GenericArrayType arrayType = (GenericArrayType) type; | ||
return hasTypeInPackage(arrayType.getGenericComponentType()); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static boolean isClassInPackage(@Nonnull Class<?> clazz) { | ||
return clazz.getName().startsWith(ICEBERG_PACKAGE_PREFIX); | ||
} | ||
} |
22 changes: 1 addition & 21 deletions
22
...g/src/main/java/io/datahubproject/iceberg/catalog/rest/common/IcebergSpringWebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters