• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSON response getting corrupted while appending using String Buffer

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a set of JSON responses from JACKSON (a High-performance JSON processor Java library) and all are fine. Next I have to append all using comma and put them enclose all of them inside the square bracket
BUT some unusual response is coming
1. It is removing the comma in between
2. It is converting the closing curly brackets to square brackets.


The individual correct responses are
{"agentId":"embedded","cacheManagerName":"MyStandAloneCacheManger","name":"2.8.0_preview-SNAPSHOT","version":"MyStandAloneCache1"}
And
{"agentId":"embedded","cacheManagerName":"MyStandAloneCacheManger","name":"2.8.0_preview-SNAPSHOT","version":"MyStandAloneCache2"}


And post appending the above two, the CORRECT output should look like
[{"agentId":"embedded","cacheManagerName":"MyStandAloneCacheManger","name":"2.8.0_preview-SNAPSHOT","version":"MyStandAloneCache1"},
{"agentId":"embedded","cacheManagerName":"MyStandAloneCacheManger","name":"2.8.0_preview-SNAPSHOT","version":"MyStandAloneCache2"}]

BUT post Stringbufffer appending its coming like as shown below

[{"agentId":"embedded","cacheManagerName":"MyStandAloneCacheManger","name":"2.8.0_preview-SNAPSHOT","version":"MyStandAloneCache1"]{"agentId":"embedded","cacheManagerName":"MyStandAloneCacheManger","name":"2.8.0_preview-SNAPSHOT","version":"MyStandAloneCache2"]

Please suggest whats wrong is happening here.
Also suggest some other means of appending the two JSON responses.

Thanks,
Faraz



 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you asking a question about code you have written? If so, you should post that code so that we know what you are asking about. However if you're asking about somebody else's code, it would help if you posted the code you have written to call their code.
 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Paul,

My main purpose of sending the query to this forum was to know if these are known issues with String Buffer.

1. It is removing the comma in between
2. It is converting the closing curly brackets to square brackets.

Let me re-verify it again and I will share the code also.

Regards,
Faraz
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, of course they aren't "known issues" with StringBuffer. The code for StringBuffer has been in Java for nearly 20 years now and it has been used by probably millions of programmers. Also since StringBuffer is a general-purpose class there is no way it would be doing specific things when it sees specific characters like curly brackets.

In general when you start having problems with code, you should always suspect your own code first. Suspecting other people's code is never a good strategy until you have eliminated the possibility that your own code is the source of the problems.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic