quarkus resteasy-jackson empty json 本机结果
quarkus resteasy-jackson empty json result for native
测试 quarkus 应用程序,使用我的 rest 端点 /init
已安装的功能:[cdi、resteasy、resteasy-jackson]
我发现当运行 app as java (not native), 然后检查
http://localhost:8080/init
{
"user": {
"username": "u name",
"firstName": "f name",
"lastName": "l name",
"email": null
},
"logoutUrl": "url!!!!"
}
作为本地人,
和运行宁像这样:
包-Dnative -f pom.xml
然后运行 ./my-service-1.0-SNAPSHOT-运行ner:
得到空结果:
http://localhost:8080/init
{}
Jackson 配置如下:
@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);
}
}
无一例外。
InitData 像这样定义,作为普通 bean class:
public class InitData {
private .. some fields
可能缺少什么?它不应该对 native/java 起作用吗?
更新:
当运行为java时,编译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]
然后点击: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
(来自 here)是在数据对象上使用的注释,如果您的资源直接 return 该数据对象。
即就我而言:
@GET
public Response getInit(
因此它不会天生工作,直到你输入:
@RegisterForReflection
class InitData { ...
但还是。
我觉得我应该是个bug。它的行为方式应该相同。是否原生。
我也认为这是一个错误,但他们在这里解释得更好: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.
测试 quarkus 应用程序,使用我的 rest 端点 /init
已安装的功能:[cdi、resteasy、resteasy-jackson]
我发现当运行 app as java (not native), 然后检查 http://localhost:8080/init
{
"user": {
"username": "u name",
"firstName": "f name",
"lastName": "l name",
"email": null
},
"logoutUrl": "url!!!!"
}
作为本地人,
和运行宁像这样: 包-Dnative -f pom.xml
然后运行 ./my-service-1.0-SNAPSHOT-运行ner:
得到空结果: http://localhost:8080/init
{}
Jackson 配置如下:
@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);
}
}
无一例外。
InitData 像这样定义,作为普通 bean class:
public class InitData {
private .. some fields
可能缺少什么?它不应该对 native/java 起作用吗?
更新:
当运行为java时,编译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]
然后点击: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
(来自 here)是在数据对象上使用的注释,如果您的资源直接 return 该数据对象。
即就我而言:
@GET
public Response getInit(
因此它不会天生工作,直到你输入:
@RegisterForReflection
class InitData { ...
但还是。
我觉得我应该是个bug。它的行为方式应该相同。是否原生。
我也认为这是一个错误,但他们在这里解释得更好: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.