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?










share|improve this question
























  • 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















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?










share|improve this question
























  • 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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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
















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












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();
}
}





share|improve this answer























  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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();
}
}





share|improve this answer























  • 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















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();
}
}





share|improve this answer























  • 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













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();
}
}





share|improve this answer














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();
}
}






share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...