Skip to content

Commit 47988a4

Browse files
authored
Merge pull request #16109 from cdapio/cherry_CDAP-21212_gson_exclude_internal_java
[cherry-pick][6.11]CDAP-21212 : Exclude Java internal classes from GSON init in Preview Data tracer
2 parents a62f7b9 + 9b04e09 commit 47988a4

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/preview/DefaultDataTracer.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16+
1617
package io.cdap.cdap.internal.app.preview;
1718

1819
import com.google.gson.Gson;
@@ -30,12 +31,28 @@
3031
import io.cdap.cdap.proto.id.ApplicationId;
3132

3233
/**
33-
* Default implementation of {@link DataTracer}, the data are preserved using {@link PreviewStore}
34+
* Default implementation of {@link DataTracer}, the data are preserved using {@link PreviewStore}.
3435
*/
3536
class DefaultDataTracer implements DataTracer {
3637

3738
private static final Gson GSON = new GsonBuilder().registerTypeAdapter(Schema.class,
3839
new SchemaTypeAdapter())
40+
// Starting java 9, some java internal modules are private and cannot be used by current
41+
// version of gson. https://cdap.atlassian.net/browse/CDAP-21212
42+
.setExclusionStrategies(new com.google.gson.ExclusionStrategy() {
43+
@Override
44+
public boolean shouldSkipField(com.google.gson.FieldAttributes f) {
45+
return false;
46+
}
47+
48+
@Override
49+
public boolean shouldSkipClass(Class<?> clazz) {
50+
String name = clazz.getName();
51+
return name.startsWith("java.lang.module")
52+
|| name.startsWith("jdk.internal")
53+
|| name.startsWith("sun.");
54+
}
55+
})
3956
.registerTypeAdapter(StructuredRecord.class, new PreviewJsonSerializer()).create();
4057

4158
private final String tracerName;

0 commit comments

Comments
 (0)