我有一个通过 RabbitMQ 作为消息发送的类,在发件人服务上,它定义如下:
public final class User implements Serializable {
private String nome;
private String cognome;
public User(@JsonProperty("nome") String nome,
@JsonProperty("cognome") String cognome) {
this.nome = nome;
this.cognome = cognome;
}
public String getNome() {
return nome;
}
public String getCognome() {
return cognome;
}
public User(){}
}
在接收方服务上:
@Document
public class Persona {
@Id
@JsonProperty
public ObjectId id;
private String nome;
private String cognome;
public String getId() {
return id.toHexString();
}
public void setId(ObjectId id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public Persona(ObjectId id, String nome, String cognome) {
this.id = id;
this.nome = nome;
this.cognome = cognome;
}
public Persona(){}
}
在接收器控制器中,我有以下方法,它应该获取该消息,将其转换为一个对象,并将其保存在数据库中,它看起来像:
@RabbitListener(queues = {"default_parser_q"})
public void receiveMessage(final Message message){
ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
mapper.readValue(message.getBody(), Persona.class);
System.out.println(message.toString() + "the message has been received");
}
问题是我在该readValue()方法上遇到异常,特别是:
未处理的异常:java.io.IOException、com.fasterxml.jackson.core.JsonParseException、com.fasterxml.jackson.databind.JsonMappingException
在这种情况下发送的消息 (JSON) 是:
{
'nome': "John",
'cognome': "Doe"
}
我在这里做错了什么?
慕娘9325324
慕田峪9158850
慕田峪7331174
偶然的你
相关分类