Spring, Apache Avro, Allargs constructor












1















I have a problem deserialising messages which have been posted to a Kafka topic. I'm using spring-boot, spring cloud stream, apache kafka, and apache avro. The object I am trying to deserialise has a constructor which takes in two args. I am getting an exception when taking a message from the topic:



org.springframework.messaging.MessagingException: Exception thrown while invoking com.foo.bar.messaging.ResponseListener#handleResponse[1 args]; 
nested exception is java.lang.RuntimeException: java.lang.NoSuchMethodException: com.foo.bar.TheObject.<init>() at org.springframework.cloud.stream.binding.StreamListenerMessageHandler.handleRequestMessage(StreamListenerMessageHandler.java:63) ~[spring-cloud-stream-2.0.1.RELEASE.jar:2.0.1.RELEASE]


The class which is being deserialised has a constructor which takes 2 args, and looks like this:



public class TheObject {
private final int thingOne;
private final int thingTwo;
@JsonCreator
public TheObject(@JsonProperty("thingOne") int thingOne, @JsonProperty("thingTwo") int thingTwo) {
this.thingOne = thingOne;
this.thingTwo = thingTwo;
}
}


Previously I used Jackson, and just posted Strings to the kafka topic, so the @JsonCreator annotation was enough to tell the mapper how to construct the object, but I'm now changing to use Arvo. Jackson is no longer used at all for this serialisation. I have left the annotations on the example above to show how it used to work.



In terms of configuration, I am using a property: dynamicSchemaGenerationEnabled: true and not explicitly declaring object schemas. This seems to be working fine with both the spring Schema Registry, and Confluent Schema Registry (apart from the problem described here)



Is there an equivalent to the @JsonCreator annotation that will work with the Arvo deserialisation?



thanks










share|improve this question

























  • for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238

    – Paizo
    Nov 19 '18 at 12:02











  • @Paizo that is not true. You do not need a 'default empty constructor' for Jackson. Jackson will already deserialise this class. The problem is that I am now using Avro, which does not use Jackson, therefore my deserialisation is no longer working

    – robjwilkins
    Nov 19 '18 at 12:09











  • Jackson supports many formats, actually. github.com/FasterXML/jackson-dataformats-binary/blob/master/… But Spring Kafka has a separate class/config for the Avro schema registry, and it's not clear if you're using that

    – cricket_007
    Nov 19 '18 at 14:00











  • I am no longer using Jackson at all. I was previously, but it has been removed. I left the annotations on the example as I want to continue using the same constructor. I have not explicitly declared a schema - I have set a property: dynamicSchemaGenerationEnabled: true

    – robjwilkins
    Nov 19 '18 at 15:17
















1















I have a problem deserialising messages which have been posted to a Kafka topic. I'm using spring-boot, spring cloud stream, apache kafka, and apache avro. The object I am trying to deserialise has a constructor which takes in two args. I am getting an exception when taking a message from the topic:



org.springframework.messaging.MessagingException: Exception thrown while invoking com.foo.bar.messaging.ResponseListener#handleResponse[1 args]; 
nested exception is java.lang.RuntimeException: java.lang.NoSuchMethodException: com.foo.bar.TheObject.<init>() at org.springframework.cloud.stream.binding.StreamListenerMessageHandler.handleRequestMessage(StreamListenerMessageHandler.java:63) ~[spring-cloud-stream-2.0.1.RELEASE.jar:2.0.1.RELEASE]


The class which is being deserialised has a constructor which takes 2 args, and looks like this:



public class TheObject {
private final int thingOne;
private final int thingTwo;
@JsonCreator
public TheObject(@JsonProperty("thingOne") int thingOne, @JsonProperty("thingTwo") int thingTwo) {
this.thingOne = thingOne;
this.thingTwo = thingTwo;
}
}


Previously I used Jackson, and just posted Strings to the kafka topic, so the @JsonCreator annotation was enough to tell the mapper how to construct the object, but I'm now changing to use Arvo. Jackson is no longer used at all for this serialisation. I have left the annotations on the example above to show how it used to work.



In terms of configuration, I am using a property: dynamicSchemaGenerationEnabled: true and not explicitly declaring object schemas. This seems to be working fine with both the spring Schema Registry, and Confluent Schema Registry (apart from the problem described here)



Is there an equivalent to the @JsonCreator annotation that will work with the Arvo deserialisation?



thanks










share|improve this question

























  • for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238

    – Paizo
    Nov 19 '18 at 12:02











  • @Paizo that is not true. You do not need a 'default empty constructor' for Jackson. Jackson will already deserialise this class. The problem is that I am now using Avro, which does not use Jackson, therefore my deserialisation is no longer working

    – robjwilkins
    Nov 19 '18 at 12:09











  • Jackson supports many formats, actually. github.com/FasterXML/jackson-dataformats-binary/blob/master/… But Spring Kafka has a separate class/config for the Avro schema registry, and it's not clear if you're using that

    – cricket_007
    Nov 19 '18 at 14:00











  • I am no longer using Jackson at all. I was previously, but it has been removed. I left the annotations on the example as I want to continue using the same constructor. I have not explicitly declared a schema - I have set a property: dynamicSchemaGenerationEnabled: true

    – robjwilkins
    Nov 19 '18 at 15:17














1












1








1








I have a problem deserialising messages which have been posted to a Kafka topic. I'm using spring-boot, spring cloud stream, apache kafka, and apache avro. The object I am trying to deserialise has a constructor which takes in two args. I am getting an exception when taking a message from the topic:



org.springframework.messaging.MessagingException: Exception thrown while invoking com.foo.bar.messaging.ResponseListener#handleResponse[1 args]; 
nested exception is java.lang.RuntimeException: java.lang.NoSuchMethodException: com.foo.bar.TheObject.<init>() at org.springframework.cloud.stream.binding.StreamListenerMessageHandler.handleRequestMessage(StreamListenerMessageHandler.java:63) ~[spring-cloud-stream-2.0.1.RELEASE.jar:2.0.1.RELEASE]


The class which is being deserialised has a constructor which takes 2 args, and looks like this:



public class TheObject {
private final int thingOne;
private final int thingTwo;
@JsonCreator
public TheObject(@JsonProperty("thingOne") int thingOne, @JsonProperty("thingTwo") int thingTwo) {
this.thingOne = thingOne;
this.thingTwo = thingTwo;
}
}


Previously I used Jackson, and just posted Strings to the kafka topic, so the @JsonCreator annotation was enough to tell the mapper how to construct the object, but I'm now changing to use Arvo. Jackson is no longer used at all for this serialisation. I have left the annotations on the example above to show how it used to work.



In terms of configuration, I am using a property: dynamicSchemaGenerationEnabled: true and not explicitly declaring object schemas. This seems to be working fine with both the spring Schema Registry, and Confluent Schema Registry (apart from the problem described here)



Is there an equivalent to the @JsonCreator annotation that will work with the Arvo deserialisation?



thanks










share|improve this question
















I have a problem deserialising messages which have been posted to a Kafka topic. I'm using spring-boot, spring cloud stream, apache kafka, and apache avro. The object I am trying to deserialise has a constructor which takes in two args. I am getting an exception when taking a message from the topic:



org.springframework.messaging.MessagingException: Exception thrown while invoking com.foo.bar.messaging.ResponseListener#handleResponse[1 args]; 
nested exception is java.lang.RuntimeException: java.lang.NoSuchMethodException: com.foo.bar.TheObject.<init>() at org.springframework.cloud.stream.binding.StreamListenerMessageHandler.handleRequestMessage(StreamListenerMessageHandler.java:63) ~[spring-cloud-stream-2.0.1.RELEASE.jar:2.0.1.RELEASE]


The class which is being deserialised has a constructor which takes 2 args, and looks like this:



public class TheObject {
private final int thingOne;
private final int thingTwo;
@JsonCreator
public TheObject(@JsonProperty("thingOne") int thingOne, @JsonProperty("thingTwo") int thingTwo) {
this.thingOne = thingOne;
this.thingTwo = thingTwo;
}
}


Previously I used Jackson, and just posted Strings to the kafka topic, so the @JsonCreator annotation was enough to tell the mapper how to construct the object, but I'm now changing to use Arvo. Jackson is no longer used at all for this serialisation. I have left the annotations on the example above to show how it used to work.



In terms of configuration, I am using a property: dynamicSchemaGenerationEnabled: true and not explicitly declaring object schemas. This seems to be working fine with both the spring Schema Registry, and Confluent Schema Registry (apart from the problem described here)



Is there an equivalent to the @JsonCreator annotation that will work with the Arvo deserialisation?



thanks







java spring apache-kafka deserialization avro






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 15:21







robjwilkins

















asked Nov 19 '18 at 11:20









robjwilkinsrobjwilkins

2,39022136




2,39022136













  • for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238

    – Paizo
    Nov 19 '18 at 12:02











  • @Paizo that is not true. You do not need a 'default empty constructor' for Jackson. Jackson will already deserialise this class. The problem is that I am now using Avro, which does not use Jackson, therefore my deserialisation is no longer working

    – robjwilkins
    Nov 19 '18 at 12:09











  • Jackson supports many formats, actually. github.com/FasterXML/jackson-dataformats-binary/blob/master/… But Spring Kafka has a separate class/config for the Avro schema registry, and it's not clear if you're using that

    – cricket_007
    Nov 19 '18 at 14:00











  • I am no longer using Jackson at all. I was previously, but it has been removed. I left the annotations on the example as I want to continue using the same constructor. I have not explicitly declared a schema - I have set a property: dynamicSchemaGenerationEnabled: true

    – robjwilkins
    Nov 19 '18 at 15:17



















  • for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238

    – Paizo
    Nov 19 '18 at 12:02











  • @Paizo that is not true. You do not need a 'default empty constructor' for Jackson. Jackson will already deserialise this class. The problem is that I am now using Avro, which does not use Jackson, therefore my deserialisation is no longer working

    – robjwilkins
    Nov 19 '18 at 12:09











  • Jackson supports many formats, actually. github.com/FasterXML/jackson-dataformats-binary/blob/master/… But Spring Kafka has a separate class/config for the Avro schema registry, and it's not clear if you're using that

    – cricket_007
    Nov 19 '18 at 14:00











  • I am no longer using Jackson at all. I was previously, but it has been removed. I left the annotations on the example as I want to continue using the same constructor. I have not explicitly declared a schema - I have set a property: dynamicSchemaGenerationEnabled: true

    – robjwilkins
    Nov 19 '18 at 15:17

















for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238

– Paizo
Nov 19 '18 at 12:02





for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238

– Paizo
Nov 19 '18 at 12:02













@Paizo that is not true. You do not need a 'default empty constructor' for Jackson. Jackson will already deserialise this class. The problem is that I am now using Avro, which does not use Jackson, therefore my deserialisation is no longer working

– robjwilkins
Nov 19 '18 at 12:09





@Paizo that is not true. You do not need a 'default empty constructor' for Jackson. Jackson will already deserialise this class. The problem is that I am now using Avro, which does not use Jackson, therefore my deserialisation is no longer working

– robjwilkins
Nov 19 '18 at 12:09













Jackson supports many formats, actually. github.com/FasterXML/jackson-dataformats-binary/blob/master/… But Spring Kafka has a separate class/config for the Avro schema registry, and it's not clear if you're using that

– cricket_007
Nov 19 '18 at 14:00





Jackson supports many formats, actually. github.com/FasterXML/jackson-dataformats-binary/blob/master/… But Spring Kafka has a separate class/config for the Avro schema registry, and it's not clear if you're using that

– cricket_007
Nov 19 '18 at 14:00













I am no longer using Jackson at all. I was previously, but it has been removed. I left the annotations on the example as I want to continue using the same constructor. I have not explicitly declared a schema - I have set a property: dynamicSchemaGenerationEnabled: true

– robjwilkins
Nov 19 '18 at 15:17





I am no longer using Jackson at all. I was previously, but it has been removed. I left the annotations on the example as I want to continue using the same constructor. I have not explicitly declared a schema - I have set a property: dynamicSchemaGenerationEnabled: true

– robjwilkins
Nov 19 '18 at 15:17












0






active

oldest

votes











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',
autoActivateHeartbeat: false,
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%2f53373541%2fspring-apache-avro-allargs-constructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373541%2fspring-apache-avro-allargs-constructor%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

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?