mertdotcc commented on issue #4124:
URL: https://github.com/apache/camel-k/issues/4124#issuecomment-1477750845
Hey @squakez and @lburgazzoli, thanks for the replies!
I followed @lburgazzoli's suggestion and am still facing some (new) issues.
Details:
I have the following integration, `MyIntegration`:
```
package com.myCompany.myProject;
// camel-k: language=java
// camel-k: name=my-project-simple-bean-native
// camel-k: dependency=camel:jackson
// camel-k: dependency=camel:jacksonxml
import com.myCompany.myProject.nativeimagetest.model.destination.MyClassA;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassB;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassC;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.quarkus.runtime.annotations.RegisterForReflection;
import javax.enterprise.context.ApplicationScoped;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
@ApplicationScoped
@RegisterForReflection(targets = {MyClassA.class, MyClassB.class,
MyClassC.class})
public class MyIntegration extends RouteBuilder {
@Override
public void configure() throws Exception {
JacksonDataFormat df = new JacksonDataFormat(MyClassA.class);
df.setEnableFeatures(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.name());
df.setObjectMapper(new ObjectMapper());
df.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
df.addModule(new JavaTimeModule());
onException(Exception.class)
.handled(true)
.setHeader("CamelHttpResponseCode").constant("400")
.setBody().simple("resource:file:/etc/camel/resources/sample-error-response.json")
.log(LoggingLevel.ERROR, "exception",
"${exception}").routeId("exception");
// GET
from("direct://getAccountById").routeId("getAccountById")
.log(LoggingLevel.INFO, "log-get", "headers: ${headers};
body: ${body}")
.setProperty("prop1").simple("${headers.prop1}")
.choice()
.when().simple("${exchangeProperty.prop1} != null")
.removeHeaders("*")
.toD("http://somewhere?bridgeEndpoint=false&connectTimeout=-1&connectionRequestTimeout=-1&disableStreamCache=true&httpMethod=GET&socketTimeout=-1&throwExceptionOnFailure=false")
.log(LoggingLevel.INFO, "body-log-1", "BODY BEFORE UNMARSHAL
${body}")
.unmarshal(df)
.log(LoggingLevel.INFO, "body-log-2", "BODY AFTER UNMARSHAL
${body}")
.to("bean:MyBean?method=handleMapping")
.marshal(df).convertBodyTo(String.class)
.endChoice()
.otherwise()
.throwException(new UnsupportedOperationException("The
operation is not supported"))
.endChoice()
.end()
.log(LoggingLevel.INFO, "get-end-log", "headers: ${headers};
body: ${body}");
}
}
```
When I call the `GET` endpoint, I receive the following error:
```
{
"status": "Invalid request",
"message":
"com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot
construct instance of `com.myCompany.myProject.clients.model.MyClassA`: cannot
deserialize from Object value (no delegate- or property-based Creator): this
appears to be a native image, in which case you may need to configure
reflection for the class that is to be deserialized
at [Source: (org.apache.camel.converter.stream.InputStreamCache); line: 2,
column: 3
]",
"exchangeId": "A27AB4B2DF324A9-0000000000000001"
}
```
I tried adding the `serialization` and `registerFullHierarchy` config
parameters to the `RegisterForReflection` annotation. So my `MyIntegration`
looked like:
```
package com.myCompany.myProject;
// camel-k: language=java
// camel-k: name=my-project-simple-bean-native
// camel-k: dependency=camel:jackson
// camel-k: dependency=camel:jacksonxml
import com.myCompany.myProject.nativeimagetest.model.destination.MyClassA;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassB;
import com.myCompany.myProject.nativeimagetest.model.source.MyClassC;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.quarkus.runtime.annotations.RegisterForReflection;
import javax.enterprise.context.ApplicationScoped;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
@ApplicationScoped
@RegisterForReflection(targets = {MyClassA.class, MyClassB.class,
MyClassC.class}, serialization = true, registerFullHierarchy = true)
public class MyIntegration extends RouteBuilder {
@Override
public void configure() throws Exception {
JacksonDataFormat df = new JacksonDataFormat(MyClassA.class);
df.setEnableFeatures(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.name());
df.setObjectMapper(new ObjectMapper());
df.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
df.addModule(new JavaTimeModule());
onException(Exception.class)
.handled(true)
.setHeader("CamelHttpResponseCode").constant("400")
.setBody().simple("resource:file:/etc/camel/resources/sample-error-response.json")
.log(LoggingLevel.ERROR, "exception",
"${exception}").routeId("exception");
// GET
from("direct://getAccountById").routeId("getAccountById")
.log(LoggingLevel.INFO, "log-get", "headers: ${headers};
body: ${body}")
.setProperty("prop1").simple("${headers.prop1}")
.choice()
.when().simple("${exchangeProperty.prop1} != null")
.removeHeaders("*")
.toD("http://somewhere?bridgeEndpoint=false&connectTimeout=-1&connectionRequestTimeout=-1&disableStreamCache=true&httpMethod=GET&socketTimeout=-1&throwExceptionOnFailure=false")
.log(LoggingLevel.INFO, "body-log-1", "BODY BEFORE UNMARSHAL
${body}")
.unmarshal(df)
.log(LoggingLevel.INFO, "body-log-2", "BODY AFTER UNMARSHAL
${body}")
.to("bean:MyBean?method=handleMapping")
.marshal(df).convertBodyTo(String.class)
.endChoice()
.otherwise()
.throwException(new UnsupportedOperationException("The
operation is not supported"))
.endChoice()
.end()
.log(LoggingLevel.INFO, "get-end-log", "headers: ${headers};
body: ${body}");
}
}
```
But I still received the same error when I called my `GET` endpoint:
```
{
"status": "Invalid request",
"message":
"com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot
construct instance of `com.myCompany.myProject.clients.model.MyClassA`: cannot
deserialize from Object value (no delegate- or property-based Creator): this
appears to be a native image, in which case you may need to configure
reflection for the class that is to be deserialized
at [Source: (org.apache.camel.converter.stream.InputStreamCache); line: 2,
column: 3
]",
"exchangeId": "A27AB4B2DF324A9-0000000000000001"
}
```
I suspected whether the reflection issue was regarding my POJOs or the
`camel-jackson` dependency, so I added the `Quarkus` annotations to all my POJO
classes (which is an approach we want to avoid in the future, as we have
hundreds of POJO classes and they are all auto-generated from our OpenApi spec
files. We don't want to take an auto-generated file and add a bunch of Quarkus
annotations to all of them) and then I got the exact same error as before:
```
{
"status": "Invalid request",
"message":
"com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot
construct instance of `com.myCompany.myProject.clients.model.MyClassA`: cannot
deserialize from Object value (no delegate- or property-based Creator): this
appears to be a native image, in which case you may need to configure
reflection for the class that is to be deserialized
at [Source: (org.apache.camel.converter.stream.InputStreamCache); line: 2,
column: 3
]",
"exchangeId": "A27AB4B2DF324A9-0000000000000001"
}
```
Feeling stuck with this and would appreciate any direction/help. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]