boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

org.boon.primitive.CharBuf.toCharArray() returns data followed by unexpected characters #340

Open har-ki opened 8 years ago

har-ki commented 8 years ago

Unlike the toString() method, the toCharArray() method does not take into account the current location. It returns the entire buffer which is 4000 chars long.

The issue manifests in objectMapper.writeValue(Writer dest, Object value) method.

Workaround is:

JsonSerializer serializer = mapper.serializer(); CharBuf serialize = serializer.serialize(myObj); writer.write(serialize.toString());

But this results in a copy and may affect performance.

har-ki commented 8 years ago

Another way to do it while avoiding the copy and preserving the performance is as follows:

JsonSerializer serializer = mapper.serializer(); CharBuf serialize = serializer.serialize(myObj); int length = serialize.length(); writer.write(serialize.readForRecycle(), 0 , length);

RichardHightower commented 8 years ago

CharBuf is a quasi internal class. If you found a good way to use it in your own project. Good job. :)

har-ki commented 8 years ago

As I mentioned in the issue notes, the issue manifests in objectMapper.writeValue(Writer dest, Object value) method because it uses CharBuf.

On Sun, Oct 18, 2015 at 10:57 PM Richard Hightower notifications@github.com wrote:

CharBuf is a quasi internal class. If you found a good way to use it in your own project. Good job. :)

— Reply to this email directly or view it on GitHub https://github.com/boonproject/boon/issues/340#issuecomment-149109680.

KowBlack commented 8 years ago

4000 bytes again... is it related to https://github.com/boonproject/boon/issues/338 ?

har-ki commented 8 years ago

Ah yes! It seems to be the same issue. On Mon, Oct 19, 2015 at 4:50 PM KowBlack notifications@github.com wrote:

4000 bytes again... is it related to #338 https://github.com/boonproject/boon/issues/338 ?

— Reply to this email directly or view it on GitHub https://github.com/boonproject/boon/issues/340#issuecomment-149379041.

RichardHightower commented 8 years ago

Please send me a test case so I can reproduce it. I reread the issue and I think I understand it better now. :)

KowBlack commented 8 years ago

I have a test case in https://github.com/boonproject/boon/issues/338