Testing quarkus app, with my rest endpoint /init
Installed features: [cdi, resteasy, resteasy-jackson]
I found that when run app as java (not native), then check http://localhost:8080/init
{
"user": {
"username": "u name",
"firstName": "f name",
"lastName": "l name",
"email": null
},
"logoutUrl": "url!!!!"
}
and as native,
And running native-ly like this: package -Dnative -f pom.xml
Then run ./my-service-1.0-SNAPSHOT-runner:
it gets empty result: http://localhost:8080/init
{}
The Jackson configure like this:
@Singleton
public class RegisterCustomModuleCustomizer implements ObjectMapperCustomizer {
public void customize(final ObjectMapper objectMapper) {
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
}
}
No exception.
InitData defined like this, as normal bean class:
public class InitData {
private .. some fields
What could be missing? In't it supposed to works same for native/java?
UPDATE:
when run as java, compile quarkus:dev -f pom.xml:
[INFO] Scanning for projects... [INFO] [INFO] ------------< my.compnay:my-service >------------ [INFO] Building my-service 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-service --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ my-service --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 41 source files to /home/me/projects/my-project/v2/my-service-quarkus/target/classes [INFO] [INFO] --- quarkus-maven-plugin:1.0.0.CR1:dev (default-cli) @ my-service --- Listening for transport dt_socket at address: 5005 2019-11-12 14:17:43,027 INFO [io.qua.dep.QuarkusAugmentor] (main) Beginning quarkus augmentation 2019-11-12 14:17:43,599 INFO [io.qua.arc.pro.BeanProcessor] (build-1) Found unrecommended usage of private members (use package-private instead) in application beans: - @Inject field my.compnay.application.InitResource#initFacadeService 2019-11-12 14:17:43,658 INFO [io.qua.dep.QuarkusAugmentor] (main) Quarkus augmentation completed in 631ms 2019-11-12 14:17:44,104 INFO [io.quarkus] (main) Quarkus 1.0.0.CR1 started in 1.260s. Listening on: http://0.0.0.0:8080 2019-11-12 14:17:44,105 INFO [io.quarkus] (main) Profile dev activated. Live Coding activated. 2019-11-12 14:17:44,105 INFO [io.quarkus] (main) Installed features: [cdi, resteasy, resteasy-jackson]
Then hit: http://localhost:8080/init
2019-11-12 14:19:52,423 INFO [com.dis.pla.app.ser.fil.LoggingFilter] (vert.x-worker-thread-1) Request GET /init from IP 0:0:0:0:0:0:0:1:48810 2019-11-12 14:19:52,425 INFO [com.dis.pla.app.InitResource] (vert.x-worker-thread-1) Init with user f name my.compnay.api.UserData@37ac6925
--
@RegisterForReflection
(from here) is the annotation to use over the Data objects IF your Resource doe snot return that data object directly.
I.e. in my case:
@GET
public Response getInit(
thus it would not work innately until you put:
@RegisterForReflection
class InitData { ...
But still.
I think I should be a bug. It should all behave same way. Native or not.
I also thought it was a bug, but they explain it better here: https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection
When building a native executable, GraalVM operates with a closed world
assumption. It analyzes the call tree and removes all the classes/methods/fields
that are not used directly.
The elements used via reflection are not part of the call tree so they are dead
code eliminated (if not called directly in other cases). To include these
elements in your native executable, you need to register them for reflection
explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With