Spring, Apache Avro, Allargs constructor
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
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
for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238
– Paizo
2 days ago
@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
2 days ago
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
2 days ago
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
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
java spring apache-kafka deserialization avro
edited 2 days ago
asked 2 days ago
robjwilkins
2,32022034
2,32022034
for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238
– Paizo
2 days ago
@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
2 days ago
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
2 days ago
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
2 days ago
add a comment |
for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238
– Paizo
2 days ago
@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
2 days ago
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
2 days ago
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
2 days ago
for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238
– Paizo
2 days ago
for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238
– Paizo
2 days ago
@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
2 days ago
@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
2 days ago
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
2 days ago
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
2 days ago
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
2 days ago
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
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53373541%2fspring-apache-avro-allargs-constructor%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
for jackson you need the default empty constructor see stackoverflow.com/a/50736606/3224238
– Paizo
2 days ago
@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
2 days ago
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
2 days ago
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
2 days ago