Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

fastjson序列化ByteBuffer的问题 #2357

Closed
zplinuxlover opened this issue Apr 8, 2019 · 1 comment
Closed

fastjson序列化ByteBuffer的问题 #2357

zplinuxlover opened this issue Apr 8, 2019 · 1 comment
Assignees
Milestone

Comments

@zplinuxlover
Copy link

zplinuxlover commented Apr 8, 2019

  1. 我的测试代码是
  @Test
    public void test() {
        ByteBuffer buff = ByteBuffer.allocate(32);
        buff.putInt(100);
        buff.flip();
        Map<String, Object> map = new HashMap<>();
        map.put("binary", buff);
        String result = JSON.toJSONString(buff);
        System.out.println(result);
    }

我使用的fastjson的代码是1.2.56版本
出现的异常是

com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.56, class java.nio.HeapByteBuffer, method : getDouble

at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:523)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:160)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:285)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:731)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:669)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:634)
at com.zhaopin.testcase.fastjson.FastJsonCodec.test(FastJsonCodec.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Caused by: java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Buffer.java:506)
at java.nio.HeapByteBuffer.getDouble(HeapByteBuffer.java:514)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.alibaba.fastjson.util.FieldInfo.get(FieldInfo.java:491)
at com.alibaba.fastjson.serializer.FieldSerializer.getPropertyValueDirect(FieldSerializer.java:149)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:291)
... 28 more

@wenshao wenshao added this to the 1.2.57 milestone Apr 9, 2019
@wenshao wenshao added type/SoC2019 Alibaba Summer of Code New Feature labels Apr 10, 2019
wenshao added a commit that referenced this issue Apr 11, 2019
@wenshao wenshao removed the type/SoC2019 Alibaba Summer of Code label Apr 11, 2019
@wenshao wenshao self-assigned this Apr 11, 2019
@wenshao
Copy link
Member

wenshao commented Apr 12, 2019

https://github.com/alibaba/fastjson/releases/tag/1.2.57
问题修复,请用新版本

@wenshao wenshao closed this as completed Apr 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants