The Funky Hermit
The Funky Hermit

Reputation: 101

Graalvm Serialization of java.lang.Integer?

I'm working on getting our Spring Boot application working with Graalvm inside a docker container.

I've been going through the process of adding classes to the reflection-config.json and serialization-config.json files and am now getting issues with basic core Java classes like Number, Integer, and Boolean.

For instance,

    2024-12-05T08:07:38.062Z ERROR 1 --- [wfprev] [nio-8080-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/wfprev-api] threw exception [Handler dispatch failed: com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: java.lang.Integer (targetConstructorClass: java.lang.Object). Usually adding java.lang.Integer to serialization-config.json fixes the problem.] 

with root cause

com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: java.lang.Integer (targetConstructorClass: java.lang.Object). Usually adding java.lang.Integer to serialization-config.json fixes the problem.

Surely I don't need to add every single java class to these config files, do I? What am I doing wrong?

Here's my serialization-config.json so far:

[
  { "name": "org.springframework.hateoas.RepresentationModel"},
  { "name": "org.springframework.hateoas.Link"},
  { "name": "org.springframework.hateoas.Links"},
  { "name": "java.util.Date"},
  { "name": "java.sql.Timestamp" },
  { "name": "java.lang.Number" },
  { "name": "java.lang.Integer" },
  { "name": "java.lang.Boolean" },
  { "name": "java.math.BigDecimal" }

]

Here's my Dockerfile in case it helps

FROM ghcr.io/graalvm/graalvm-community:21 AS builder

# Define build argument and set it as environment variable
ARG MAVEN_SETTINGS_FILE=settings.xml

ENV MAVEN_SETTINGS_FILE=${MAVEN_SETTINGS_FILE}

# The environment variables from .env are automatically available here
# We don't need the ARG declarations anymore since we're using the env file

WORKDIR /app

# Copy maven settings first
COPY mvn_settings/${MAVEN_SETTINGS_FILE} /root/.m2/settings.xml

# Copy rest of the application
COPY . /app

# Make mvnw executable
RUN chmod +x mvnw

# Build the native image using settings.xml
RUN ./mvnw -s mvn_settings/${MAVEN_SETTINGS_FILE} -Pnative native:compile -DskipTests

# Runtime stage
FROM ubuntu:22.04

# Install curl for healthcheck and debugging
RUN apt-get update && apt-get install -y \
    libc6 \
    libstdc++6 \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy the native executable from builder stage
COPY --from=builder /app/target/wfprev-api /

# Expose the port your application uses
EXPOSE 8080

ENTRYPOINT ["/wfprev-api"]```

Upvotes: 0

Views: 77

Answers (0)

Related Questions