Apache Camel Rest Custom Json Deserializer
up vote
0
down vote
favorite
I use Camel 2.16.0 for a Camel Rest project. I have introduced an abstract type that I need a custom deserializer to handle. This works as expected in my deserialization unit tests where I register my custom deserializer to the Objectmapper for the tests. To my understanding it is possible to register custom modules to the Jackson Objectmapper used by Camel as well (camel json).
My configuration:
...
<camelContext id="formsContext" xmlns="http://camel.apache.org/schema/spring">
...
<dataFormats>
<json id="json" library="Jackson" useList="true" unmarshalTypeName="myPackage.model.CustomDeserialized" moduleClassNames="myPackage.MyModule" />
</dataFormats>
</camelContext>
My module:
package myPackage;
import com.fasterxml.jackson.databind.module.SimpleModule;
public class MyModule extends SimpleModule {
public MyModule() {
super();
addDeserializer(CustomDeserialized.class, new MyDeserializer());
}
}
The Camel rest configuration:
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.contextPath("/")
.port(8080)
.jsonDataFormat("json");
When running the service and invoking a function that utilize the objectmapper I get the exception:
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of myPackage.model.CustomDeserialized, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
Any suggestions on what is wrong with my setup?
json apache-camel deserialization jackson-databind
add a comment |
up vote
0
down vote
favorite
I use Camel 2.16.0 for a Camel Rest project. I have introduced an abstract type that I need a custom deserializer to handle. This works as expected in my deserialization unit tests where I register my custom deserializer to the Objectmapper for the tests. To my understanding it is possible to register custom modules to the Jackson Objectmapper used by Camel as well (camel json).
My configuration:
...
<camelContext id="formsContext" xmlns="http://camel.apache.org/schema/spring">
...
<dataFormats>
<json id="json" library="Jackson" useList="true" unmarshalTypeName="myPackage.model.CustomDeserialized" moduleClassNames="myPackage.MyModule" />
</dataFormats>
</camelContext>
My module:
package myPackage;
import com.fasterxml.jackson.databind.module.SimpleModule;
public class MyModule extends SimpleModule {
public MyModule() {
super();
addDeserializer(CustomDeserialized.class, new MyDeserializer());
}
}
The Camel rest configuration:
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.contextPath("/")
.port(8080)
.jsonDataFormat("json");
When running the service and invoking a function that utilize the objectmapper I get the exception:
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of myPackage.model.CustomDeserialized, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
Any suggestions on what is wrong with my setup?
json apache-camel deserialization jackson-databind
I used an external library to addhal+json
support to a test-project of mine. Basically I define my own version ofDefaultDataFormatResolver
and register it with the camel context.
– Roman Vottner
Nov 23 at 14:28
Within the rest configuration I was able to add the custom data format then. Not sure if this is what you are asking for exactly. This also works only for an either all or nothing approach. If you only need one route to support this "feature" this is probably not the correct approach unfortunately
– Roman Vottner
Nov 23 at 14:30
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I use Camel 2.16.0 for a Camel Rest project. I have introduced an abstract type that I need a custom deserializer to handle. This works as expected in my deserialization unit tests where I register my custom deserializer to the Objectmapper for the tests. To my understanding it is possible to register custom modules to the Jackson Objectmapper used by Camel as well (camel json).
My configuration:
...
<camelContext id="formsContext" xmlns="http://camel.apache.org/schema/spring">
...
<dataFormats>
<json id="json" library="Jackson" useList="true" unmarshalTypeName="myPackage.model.CustomDeserialized" moduleClassNames="myPackage.MyModule" />
</dataFormats>
</camelContext>
My module:
package myPackage;
import com.fasterxml.jackson.databind.module.SimpleModule;
public class MyModule extends SimpleModule {
public MyModule() {
super();
addDeserializer(CustomDeserialized.class, new MyDeserializer());
}
}
The Camel rest configuration:
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.contextPath("/")
.port(8080)
.jsonDataFormat("json");
When running the service and invoking a function that utilize the objectmapper I get the exception:
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of myPackage.model.CustomDeserialized, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
Any suggestions on what is wrong with my setup?
json apache-camel deserialization jackson-databind
I use Camel 2.16.0 for a Camel Rest project. I have introduced an abstract type that I need a custom deserializer to handle. This works as expected in my deserialization unit tests where I register my custom deserializer to the Objectmapper for the tests. To my understanding it is possible to register custom modules to the Jackson Objectmapper used by Camel as well (camel json).
My configuration:
...
<camelContext id="formsContext" xmlns="http://camel.apache.org/schema/spring">
...
<dataFormats>
<json id="json" library="Jackson" useList="true" unmarshalTypeName="myPackage.model.CustomDeserialized" moduleClassNames="myPackage.MyModule" />
</dataFormats>
</camelContext>
My module:
package myPackage;
import com.fasterxml.jackson.databind.module.SimpleModule;
public class MyModule extends SimpleModule {
public MyModule() {
super();
addDeserializer(CustomDeserialized.class, new MyDeserializer());
}
}
The Camel rest configuration:
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true")
.contextPath("/")
.port(8080)
.jsonDataFormat("json");
When running the service and invoking a function that utilize the objectmapper I get the exception:
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of myPackage.model.CustomDeserialized, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
Any suggestions on what is wrong with my setup?
json apache-camel deserialization jackson-databind
json apache-camel deserialization jackson-databind
edited Nov 23 at 14:35
Roman Vottner
5,53612436
5,53612436
asked Nov 21 at 8:36
Lynge
114
114
I used an external library to addhal+json
support to a test-project of mine. Basically I define my own version ofDefaultDataFormatResolver
and register it with the camel context.
– Roman Vottner
Nov 23 at 14:28
Within the rest configuration I was able to add the custom data format then. Not sure if this is what you are asking for exactly. This also works only for an either all or nothing approach. If you only need one route to support this "feature" this is probably not the correct approach unfortunately
– Roman Vottner
Nov 23 at 14:30
add a comment |
I used an external library to addhal+json
support to a test-project of mine. Basically I define my own version ofDefaultDataFormatResolver
and register it with the camel context.
– Roman Vottner
Nov 23 at 14:28
Within the rest configuration I was able to add the custom data format then. Not sure if this is what you are asking for exactly. This also works only for an either all or nothing approach. If you only need one route to support this "feature" this is probably not the correct approach unfortunately
– Roman Vottner
Nov 23 at 14:30
I used an external library to add
hal+json
support to a test-project of mine. Basically I define my own version of DefaultDataFormatResolver
and register it with the camel context.– Roman Vottner
Nov 23 at 14:28
I used an external library to add
hal+json
support to a test-project of mine. Basically I define my own version of DefaultDataFormatResolver
and register it with the camel context.– Roman Vottner
Nov 23 at 14:28
Within the rest configuration I was able to add the custom data format then. Not sure if this is what you are asking for exactly. This also works only for an either all or nothing approach. If you only need one route to support this "feature" this is probably not the correct approach unfortunately
– Roman Vottner
Nov 23 at 14:30
Within the rest configuration I was able to add the custom data format then. Not sure if this is what you are asking for exactly. This also works only for an either all or nothing approach. If you only need one route to support this "feature" this is probably not the correct approach unfortunately
– Roman Vottner
Nov 23 at 14:30
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I found this solution to the problem and used this implementation for my custom jackson dataformat:
public class JacksonDataFormatExtension extends JacksonDataFormat {
public JacksonDataFormatExtension() {
super(CustomDeserialized.class);
}
protected void doStart() throws Exception {
addModule(new MyModule());
super.doStart();
}
}
Please don't edit your solution into the original post but add it to you answer. You can self-answer question here on SO without any considerations. Please also accept your answer as soon as possible to help others in future to resolve a similar issue more easily :)
– Roman Vottner
Nov 23 at 14:37
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I found this solution to the problem and used this implementation for my custom jackson dataformat:
public class JacksonDataFormatExtension extends JacksonDataFormat {
public JacksonDataFormatExtension() {
super(CustomDeserialized.class);
}
protected void doStart() throws Exception {
addModule(new MyModule());
super.doStart();
}
}
Please don't edit your solution into the original post but add it to you answer. You can self-answer question here on SO without any considerations. Please also accept your answer as soon as possible to help others in future to resolve a similar issue more easily :)
– Roman Vottner
Nov 23 at 14:37
add a comment |
up vote
1
down vote
accepted
I found this solution to the problem and used this implementation for my custom jackson dataformat:
public class JacksonDataFormatExtension extends JacksonDataFormat {
public JacksonDataFormatExtension() {
super(CustomDeserialized.class);
}
protected void doStart() throws Exception {
addModule(new MyModule());
super.doStart();
}
}
Please don't edit your solution into the original post but add it to you answer. You can self-answer question here on SO without any considerations. Please also accept your answer as soon as possible to help others in future to resolve a similar issue more easily :)
– Roman Vottner
Nov 23 at 14:37
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I found this solution to the problem and used this implementation for my custom jackson dataformat:
public class JacksonDataFormatExtension extends JacksonDataFormat {
public JacksonDataFormatExtension() {
super(CustomDeserialized.class);
}
protected void doStart() throws Exception {
addModule(new MyModule());
super.doStart();
}
}
I found this solution to the problem and used this implementation for my custom jackson dataformat:
public class JacksonDataFormatExtension extends JacksonDataFormat {
public JacksonDataFormatExtension() {
super(CustomDeserialized.class);
}
protected void doStart() throws Exception {
addModule(new MyModule());
super.doStart();
}
}
edited Nov 23 at 14:34
Roman Vottner
5,53612436
5,53612436
answered Nov 23 at 14:00
Lynge
114
114
Please don't edit your solution into the original post but add it to you answer. You can self-answer question here on SO without any considerations. Please also accept your answer as soon as possible to help others in future to resolve a similar issue more easily :)
– Roman Vottner
Nov 23 at 14:37
add a comment |
Please don't edit your solution into the original post but add it to you answer. You can self-answer question here on SO without any considerations. Please also accept your answer as soon as possible to help others in future to resolve a similar issue more easily :)
– Roman Vottner
Nov 23 at 14:37
Please don't edit your solution into the original post but add it to you answer. You can self-answer question here on SO without any considerations. Please also accept your answer as soon as possible to help others in future to resolve a similar issue more easily :)
– Roman Vottner
Nov 23 at 14:37
Please don't edit your solution into the original post but add it to you answer. You can self-answer question here on SO without any considerations. Please also accept your answer as soon as possible to help others in future to resolve a similar issue more easily :)
– Roman Vottner
Nov 23 at 14:37
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408055%2fapache-camel-rest-custom-json-deserializer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I used an external library to add
hal+json
support to a test-project of mine. Basically I define my own version ofDefaultDataFormatResolver
and register it with the camel context.– Roman Vottner
Nov 23 at 14:28
Within the rest configuration I was able to add the custom data format then. Not sure if this is what you are asking for exactly. This also works only for an either all or nothing approach. If you only need one route to support this "feature" this is probably not the correct approach unfortunately
– Roman Vottner
Nov 23 at 14:30