JsonParseException: Unexpected character ('i' (code 105)): was expecting double-quote
I am trying to integrate Spring Cloud streams and publishing a custom Java Object across services with RabbitMQ as broker. The object I am publishing looks like:
public class AppMessageEnvelope implements Serializable {
...
private Object messageBody;
private Date sentAt = new Date();
...
// setters and getters
}
This is just a wrapper object and the original object is put in messageBody
. The object I am putting in messageBody
looks like:
public class Job {
...
private String message;
private Map<MyEnum, String> myMap;
...
}
Note that both AppMessageEnvelope
and Job
are in a different model project which is imported as a Maven dependency in the publisher and subscriber Spring Boot projects, so models are exactly the same.
In producer, I publish the object as:
@EnableBinding(Source.class)
public class JobDistributor {
private final Source jobQueue;
@Autowired
public JobDistributor(Source jobQueue) {
this.jobQueue = jobQueue;
}
public AppMessageEnvelope publishJob(AppMessageEnvelope message) {
LOG.info("Sending message: {}.", message);
jobQueue.output().send(MessageBuilder.withPayload(message).build());
return message;
}
}
In consumer, I get the message as:
@Component
@EnableBinding(Sink.class)
public class JobConsumer {
private final JobManager jobManager;
private final ObjectMapper objectMapper;
@Autowired
public JobConsumer(
JobManager jobManager, ObjectMapper objectMapper) {
this.jobManager = jobManager;
this.objectMapper = objectMapper;
}
@StreamListener(target = Sink.INPUT)
public void processData(AppMessageEnvelope messageEnvelope) {
LOG.info("Envelope received: {}.", messageEnvelope);
try {
TypeReference<Job> mapType = new TypeReference<Job>() {};
Job job = objectMapper.readValue(messageEnvelope.getMessageBody().toString(), mapType);
jobManager.processRequest(job);
} catch (Exception ex) {
LOG.error("Couldn't convert to correct object for processing: {}.", ex);
}
}
}
I try to use TypeReference
to convert the internal object into a correct object but I get an error as:
JobConsumer - Couldn't convert to correct object for processing: {}.
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('i' (code 105)): was expecting double-quote to start field name
at [Source: (StringReader); line: 1, column: 3]
Before the message is converted, I log it:
JobConsumer - Envelope received: AppMessageEnvelope{..., messageBody={id=5bf3a7302dbe9c7cf9927c60, jobId=8c0bfcb0b21248e694b5cd52337a1f9e, submittedAt=2018-11-20T06:18:24+0000, lastUpdatedOn=null, message=null, ..., fileContentMap={FILE_BYTES=JVBERi0xLjUKJb/3ov}}, sentAt=Tue Nov 20 11:48:24 IST 2018}
I tried configuring ObjectMapper
as:
@Autowired
private ObjectMapper objectMapper() {
JsonFactory factory = new JsonFactory();
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
return new ObjectMapper(factory);
}
I tried enabling unquoting fields with this too:
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
I tried solutions provided by this blog and some similar SO problem but nothing solved. What am I missing?
java serialization rabbitmq spring-cloud-stream
|
show 2 more comments
I am trying to integrate Spring Cloud streams and publishing a custom Java Object across services with RabbitMQ as broker. The object I am publishing looks like:
public class AppMessageEnvelope implements Serializable {
...
private Object messageBody;
private Date sentAt = new Date();
...
// setters and getters
}
This is just a wrapper object and the original object is put in messageBody
. The object I am putting in messageBody
looks like:
public class Job {
...
private String message;
private Map<MyEnum, String> myMap;
...
}
Note that both AppMessageEnvelope
and Job
are in a different model project which is imported as a Maven dependency in the publisher and subscriber Spring Boot projects, so models are exactly the same.
In producer, I publish the object as:
@EnableBinding(Source.class)
public class JobDistributor {
private final Source jobQueue;
@Autowired
public JobDistributor(Source jobQueue) {
this.jobQueue = jobQueue;
}
public AppMessageEnvelope publishJob(AppMessageEnvelope message) {
LOG.info("Sending message: {}.", message);
jobQueue.output().send(MessageBuilder.withPayload(message).build());
return message;
}
}
In consumer, I get the message as:
@Component
@EnableBinding(Sink.class)
public class JobConsumer {
private final JobManager jobManager;
private final ObjectMapper objectMapper;
@Autowired
public JobConsumer(
JobManager jobManager, ObjectMapper objectMapper) {
this.jobManager = jobManager;
this.objectMapper = objectMapper;
}
@StreamListener(target = Sink.INPUT)
public void processData(AppMessageEnvelope messageEnvelope) {
LOG.info("Envelope received: {}.", messageEnvelope);
try {
TypeReference<Job> mapType = new TypeReference<Job>() {};
Job job = objectMapper.readValue(messageEnvelope.getMessageBody().toString(), mapType);
jobManager.processRequest(job);
} catch (Exception ex) {
LOG.error("Couldn't convert to correct object for processing: {}.", ex);
}
}
}
I try to use TypeReference
to convert the internal object into a correct object but I get an error as:
JobConsumer - Couldn't convert to correct object for processing: {}.
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('i' (code 105)): was expecting double-quote to start field name
at [Source: (StringReader); line: 1, column: 3]
Before the message is converted, I log it:
JobConsumer - Envelope received: AppMessageEnvelope{..., messageBody={id=5bf3a7302dbe9c7cf9927c60, jobId=8c0bfcb0b21248e694b5cd52337a1f9e, submittedAt=2018-11-20T06:18:24+0000, lastUpdatedOn=null, message=null, ..., fileContentMap={FILE_BYTES=JVBERi0xLjUKJb/3ov}}, sentAt=Tue Nov 20 11:48:24 IST 2018}
I tried configuring ObjectMapper
as:
@Autowired
private ObjectMapper objectMapper() {
JsonFactory factory = new JsonFactory();
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
return new ObjectMapper(factory);
}
I tried enabling unquoting fields with this too:
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
I tried solutions provided by this blog and some similar SO problem but nothing solved. What am I missing?
java serialization rabbitmq spring-cloud-stream
1
Can you please try this return new ObjectMapper().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
– Raheela Aslam
Nov 20 '18 at 6:42
Sorry I missed that I tried this as well. Let me add this to the OP.
– Shubham A.
Nov 20 '18 at 6:47
Can you please check your JSON is vaild. Please also have a look into stackoverflow.com/questions/4815231/…
– Raheela Aslam
Nov 20 '18 at 6:53
Yes it is. I mean publisher publishes it as a POJO so it is internally converted into JSON and consumer accepts the object asAppMessageEnvelope
and no problem happens there. The problem is when it tries to convert internal object.
– Shubham A.
Nov 20 '18 at 6:55
What is printed when you printmessageEnvelope.getMessageBody().toString()
andmessageEnvelope.getMessageBody().getClass()
?
– JB Nizet
Nov 20 '18 at 7:06
|
show 2 more comments
I am trying to integrate Spring Cloud streams and publishing a custom Java Object across services with RabbitMQ as broker. The object I am publishing looks like:
public class AppMessageEnvelope implements Serializable {
...
private Object messageBody;
private Date sentAt = new Date();
...
// setters and getters
}
This is just a wrapper object and the original object is put in messageBody
. The object I am putting in messageBody
looks like:
public class Job {
...
private String message;
private Map<MyEnum, String> myMap;
...
}
Note that both AppMessageEnvelope
and Job
are in a different model project which is imported as a Maven dependency in the publisher and subscriber Spring Boot projects, so models are exactly the same.
In producer, I publish the object as:
@EnableBinding(Source.class)
public class JobDistributor {
private final Source jobQueue;
@Autowired
public JobDistributor(Source jobQueue) {
this.jobQueue = jobQueue;
}
public AppMessageEnvelope publishJob(AppMessageEnvelope message) {
LOG.info("Sending message: {}.", message);
jobQueue.output().send(MessageBuilder.withPayload(message).build());
return message;
}
}
In consumer, I get the message as:
@Component
@EnableBinding(Sink.class)
public class JobConsumer {
private final JobManager jobManager;
private final ObjectMapper objectMapper;
@Autowired
public JobConsumer(
JobManager jobManager, ObjectMapper objectMapper) {
this.jobManager = jobManager;
this.objectMapper = objectMapper;
}
@StreamListener(target = Sink.INPUT)
public void processData(AppMessageEnvelope messageEnvelope) {
LOG.info("Envelope received: {}.", messageEnvelope);
try {
TypeReference<Job> mapType = new TypeReference<Job>() {};
Job job = objectMapper.readValue(messageEnvelope.getMessageBody().toString(), mapType);
jobManager.processRequest(job);
} catch (Exception ex) {
LOG.error("Couldn't convert to correct object for processing: {}.", ex);
}
}
}
I try to use TypeReference
to convert the internal object into a correct object but I get an error as:
JobConsumer - Couldn't convert to correct object for processing: {}.
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('i' (code 105)): was expecting double-quote to start field name
at [Source: (StringReader); line: 1, column: 3]
Before the message is converted, I log it:
JobConsumer - Envelope received: AppMessageEnvelope{..., messageBody={id=5bf3a7302dbe9c7cf9927c60, jobId=8c0bfcb0b21248e694b5cd52337a1f9e, submittedAt=2018-11-20T06:18:24+0000, lastUpdatedOn=null, message=null, ..., fileContentMap={FILE_BYTES=JVBERi0xLjUKJb/3ov}}, sentAt=Tue Nov 20 11:48:24 IST 2018}
I tried configuring ObjectMapper
as:
@Autowired
private ObjectMapper objectMapper() {
JsonFactory factory = new JsonFactory();
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
return new ObjectMapper(factory);
}
I tried enabling unquoting fields with this too:
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
I tried solutions provided by this blog and some similar SO problem but nothing solved. What am I missing?
java serialization rabbitmq spring-cloud-stream
I am trying to integrate Spring Cloud streams and publishing a custom Java Object across services with RabbitMQ as broker. The object I am publishing looks like:
public class AppMessageEnvelope implements Serializable {
...
private Object messageBody;
private Date sentAt = new Date();
...
// setters and getters
}
This is just a wrapper object and the original object is put in messageBody
. The object I am putting in messageBody
looks like:
public class Job {
...
private String message;
private Map<MyEnum, String> myMap;
...
}
Note that both AppMessageEnvelope
and Job
are in a different model project which is imported as a Maven dependency in the publisher and subscriber Spring Boot projects, so models are exactly the same.
In producer, I publish the object as:
@EnableBinding(Source.class)
public class JobDistributor {
private final Source jobQueue;
@Autowired
public JobDistributor(Source jobQueue) {
this.jobQueue = jobQueue;
}
public AppMessageEnvelope publishJob(AppMessageEnvelope message) {
LOG.info("Sending message: {}.", message);
jobQueue.output().send(MessageBuilder.withPayload(message).build());
return message;
}
}
In consumer, I get the message as:
@Component
@EnableBinding(Sink.class)
public class JobConsumer {
private final JobManager jobManager;
private final ObjectMapper objectMapper;
@Autowired
public JobConsumer(
JobManager jobManager, ObjectMapper objectMapper) {
this.jobManager = jobManager;
this.objectMapper = objectMapper;
}
@StreamListener(target = Sink.INPUT)
public void processData(AppMessageEnvelope messageEnvelope) {
LOG.info("Envelope received: {}.", messageEnvelope);
try {
TypeReference<Job> mapType = new TypeReference<Job>() {};
Job job = objectMapper.readValue(messageEnvelope.getMessageBody().toString(), mapType);
jobManager.processRequest(job);
} catch (Exception ex) {
LOG.error("Couldn't convert to correct object for processing: {}.", ex);
}
}
}
I try to use TypeReference
to convert the internal object into a correct object but I get an error as:
JobConsumer - Couldn't convert to correct object for processing: {}.
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('i' (code 105)): was expecting double-quote to start field name
at [Source: (StringReader); line: 1, column: 3]
Before the message is converted, I log it:
JobConsumer - Envelope received: AppMessageEnvelope{..., messageBody={id=5bf3a7302dbe9c7cf9927c60, jobId=8c0bfcb0b21248e694b5cd52337a1f9e, submittedAt=2018-11-20T06:18:24+0000, lastUpdatedOn=null, message=null, ..., fileContentMap={FILE_BYTES=JVBERi0xLjUKJb/3ov}}, sentAt=Tue Nov 20 11:48:24 IST 2018}
I tried configuring ObjectMapper
as:
@Autowired
private ObjectMapper objectMapper() {
JsonFactory factory = new JsonFactory();
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
return new ObjectMapper(factory);
}
I tried enabling unquoting fields with this too:
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
I tried solutions provided by this blog and some similar SO problem but nothing solved. What am I missing?
java serialization rabbitmq spring-cloud-stream
java serialization rabbitmq spring-cloud-stream
edited Nov 20 '18 at 6:49
Shubham A.
asked Nov 20 '18 at 6:36
Shubham A.Shubham A.
1,42011841
1,42011841
1
Can you please try this return new ObjectMapper().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
– Raheela Aslam
Nov 20 '18 at 6:42
Sorry I missed that I tried this as well. Let me add this to the OP.
– Shubham A.
Nov 20 '18 at 6:47
Can you please check your JSON is vaild. Please also have a look into stackoverflow.com/questions/4815231/…
– Raheela Aslam
Nov 20 '18 at 6:53
Yes it is. I mean publisher publishes it as a POJO so it is internally converted into JSON and consumer accepts the object asAppMessageEnvelope
and no problem happens there. The problem is when it tries to convert internal object.
– Shubham A.
Nov 20 '18 at 6:55
What is printed when you printmessageEnvelope.getMessageBody().toString()
andmessageEnvelope.getMessageBody().getClass()
?
– JB Nizet
Nov 20 '18 at 7:06
|
show 2 more comments
1
Can you please try this return new ObjectMapper().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
– Raheela Aslam
Nov 20 '18 at 6:42
Sorry I missed that I tried this as well. Let me add this to the OP.
– Shubham A.
Nov 20 '18 at 6:47
Can you please check your JSON is vaild. Please also have a look into stackoverflow.com/questions/4815231/…
– Raheela Aslam
Nov 20 '18 at 6:53
Yes it is. I mean publisher publishes it as a POJO so it is internally converted into JSON and consumer accepts the object asAppMessageEnvelope
and no problem happens there. The problem is when it tries to convert internal object.
– Shubham A.
Nov 20 '18 at 6:55
What is printed when you printmessageEnvelope.getMessageBody().toString()
andmessageEnvelope.getMessageBody().getClass()
?
– JB Nizet
Nov 20 '18 at 7:06
1
1
Can you please try this return new ObjectMapper().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
– Raheela Aslam
Nov 20 '18 at 6:42
Can you please try this return new ObjectMapper().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
– Raheela Aslam
Nov 20 '18 at 6:42
Sorry I missed that I tried this as well. Let me add this to the OP.
– Shubham A.
Nov 20 '18 at 6:47
Sorry I missed that I tried this as well. Let me add this to the OP.
– Shubham A.
Nov 20 '18 at 6:47
Can you please check your JSON is vaild. Please also have a look into stackoverflow.com/questions/4815231/…
– Raheela Aslam
Nov 20 '18 at 6:53
Can you please check your JSON is vaild. Please also have a look into stackoverflow.com/questions/4815231/…
– Raheela Aslam
Nov 20 '18 at 6:53
Yes it is. I mean publisher publishes it as a POJO so it is internally converted into JSON and consumer accepts the object as
AppMessageEnvelope
and no problem happens there. The problem is when it tries to convert internal object.– Shubham A.
Nov 20 '18 at 6:55
Yes it is. I mean publisher publishes it as a POJO so it is internally converted into JSON and consumer accepts the object as
AppMessageEnvelope
and no problem happens there. The problem is when it tries to convert internal object.– Shubham A.
Nov 20 '18 at 6:55
What is printed when you print
messageEnvelope.getMessageBody().toString()
and messageEnvelope.getMessageBody().getClass()
?– JB Nizet
Nov 20 '18 at 7:06
What is printed when you print
messageEnvelope.getMessageBody().toString()
and messageEnvelope.getMessageBody().getClass()
?– JB Nizet
Nov 20 '18 at 7:06
|
show 2 more comments
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
});
}
});
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%2f53387516%2fjsonparseexception-unexpected-character-i-code-105-was-expecting-double%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
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.
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%2f53387516%2fjsonparseexception-unexpected-character-i-code-105-was-expecting-double%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
1
Can you please try this return new ObjectMapper().configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
– Raheela Aslam
Nov 20 '18 at 6:42
Sorry I missed that I tried this as well. Let me add this to the OP.
– Shubham A.
Nov 20 '18 at 6:47
Can you please check your JSON is vaild. Please also have a look into stackoverflow.com/questions/4815231/…
– Raheela Aslam
Nov 20 '18 at 6:53
Yes it is. I mean publisher publishes it as a POJO so it is internally converted into JSON and consumer accepts the object as
AppMessageEnvelope
and no problem happens there. The problem is when it tries to convert internal object.– Shubham A.
Nov 20 '18 at 6:55
What is printed when you print
messageEnvelope.getMessageBody().toString()
andmessageEnvelope.getMessageBody().getClass()
?– JB Nizet
Nov 20 '18 at 7:06