micronaut-projects / micronaut-discovery-client

Micronaut's Discovery Client
Apache License 2.0
20 stars 18 forks source link

Registration with Eureka doesn't work when using Micronaut serialization #552

Open AlucardHs opened 9 months ago

AlucardHs commented 9 months ago

Expected Behavior

Registration with Eureka should work when using Micronaut serialization just as it does when using Jackson serialization.

Actual Behaviour

During registration, Micronaut reports an error that PortWrapper could not be serialized:

Caused by: io.micronaut.serde.exceptions.SerdeException: No serializable introspection present for type PortWrapper portWrapper. Consider adding Serdeable. Serializable annotate to type PortWrapper portWrapper. Alternatively if you are not in control of the project's source code, you can use @SerdeImport(PortWrapper.class) to enable serialization of this type. at io.micronaut.serde.support.serializers.ObjectSerializer$4.tryToFindSerializer(ObjectSerializer.java:218) at io.micronaut.serde.support.serializers.ObjectSerializer$RuntimeTypeSerializer.lambda$getSerializer$0(ObjectSerializer.java:280) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) at io.micronaut.serde.support.serializers.ObjectSerializer$RuntimeTypeSerializer.getSerializer(ObjectSerializer.java:278) at io.micronaut.serde.support.serializers.ObjectSerializer$RuntimeTypeSerializer.serialize(ObjectSerializer.java:245) at io.micronaut.serde.support.serializers.CustomizedObjectSerializer.serialize(CustomizedObjectSerializer.java:132) at io.micronaut.serde.support.serializers.ObjectSerializer$RuntimeTypeSerializer.serialize(ObjectSerializer.java:245) at io.micronaut.serde.jackson.JacksonJsonMapper.writeValue(JacksonJsonMapper.java:114) at io.micronaut.serde.jackson.JacksonJsonMapper.writeValue(JacksonJsonMapper.java:193) at io.micronaut.json.body.JsonMessageHandler.writeTo(JsonMessageHandler.java:136) ... 45 common frames omitted

This seems like an easy fix – just adding @Serdeable to PortWrapper. However, when I clone the code and add the @Serdeable annotation to the PortWrapper, the registration still doesn't work. This time, the issue is with serializing the DataCenterInfo class. On the discovery service side (spring boot application), the following exception is logged (trimmed for conciseness):

com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class com.netflix.appinfo.DataCenterInfo]: missing type id property '@class' at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 707] at com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43) ~[jackson-databind-2.14.1.jar:2.14.1] at com.fasterxml.jackson.databind.DeserializationContext.missingTypeIdException(DeserializationContext.java:2088) ~[jackson-databind-2.14.1.jar:2.14.1]

Looking at what's being sent, it seems that Micronaut serialization indeed does not include the @class attribute into the json. Here's the resulting json:

{"instance":{"hostName":"localhost","port":{"@enabled":true,"$":8099},"securePort":{"@enabled":false,"$":0},"app":"transaction-service","instanceId":"transaction-service:8099","countryId":1,"ipAddr":"127.0.0.1","status":"UP","dataCenterInfo":{"dataCenterInfo":{"name":"MyOwn"},"leaseInfo":{"leaseInfo":{"registrationTimestamp":0,"lastRenewalTimestamp":0,"evictionTimestamp":0,"serviceUpTimestamp":0,"renewalIntervalInSecs":30,"durationInSecs":90},"statusPageUrl":"http://localhost:8099/health","homePageUrl":"http://localhost:8099","healthCheckUrl":"http://localhost:8099/health","vipAddress":"transaction-service","secureVipAddress":"transaction-service","secureHealthCheckUrl":"https://localhost/health"}}}}]

Steps To Reproduce

  1. Create a sample project using Micronaut Launch with a single feature of eureka-discovery (Java 17 + Maven).
  2. No changes to generated pom.xml are necessary (attached)
  3. Use the standard configuration for Eureka and make sure Eureka server is running on that port:
    micronaut.application.name=demo
    eureka.client.defaultZone=${EUREKA_HOST\:localhost}\:${EUREKA_PORT\:8761}
    eureka.client.registration.enabled=true
  4. Run the application
  5. After adding the @Serdeable to the PortWrapper class, repeat the steps to see the second failure pom.txt

Environment Information

Example Application

No response

Version

4.2.0

AkshathSai commented 1 month ago

Is there any outcome? I encountered the same issue

yakovliam commented 3 weeks ago

Hi, experiencing the same issue. This is a very serious bug! The solution I found is to remove serde from the project (which is not ideal...it's a useful library) and instead use micronaut-jackson-databind.