• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Concatenation is failing  RSS feed

 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to concatenate some strings via: String finalString="(User="+endUserCharge+")"; endUserCharge is a string

I get the following error:

caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('(' (code 40)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.ByteArrayInputStream@3d9127a9; line: 1, column: 2]
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what's behind the scene of your code, but it is worth to go through https://docs.oracle.com/javase/tutorial/java/data/strings.html
So you could find how String concatenation is achieved.
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the parser think this is JSON? This isn't JavaScript, is it?

I bet some surrounding code will make it clear.
 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I was doing for concatenation was legal. After sticking some system.out.println before and after the assignment statement, I was able to track down that the concatenation actually worked and the failure was downstream from the concatenation.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're trying to parse this string as if it is in JSON format, but a string that looks like "(User=whatever)" is not valid JSON.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Piaser wrote:I get the following error:

caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('(' (code 40)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.ByteArrayInputStream@3d9127a9; line: 1, column: 2]

There was probably a little more to the error message than this. you should learn how to read the stack trace to see where the JVM thinks the error is. Sometimes you have to dig a bit, but somewhere it should have referred to a line of YOUR code, not a piece of a class provided as part of Java - then you can look there for the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!