fastjson Json转换出错

9o685dep  于 3个月前  发布在  其他
关注(0)|答案(3)|浏览(79)

我用EMF建模出来的java数据模型想用fastjson序列化为json结果报错:

com.alibaba.fastjson.JSONException: write javaBean error, class org.eclipse.emf.ecore.impl.EClassImpl, fieldName : 0, org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl cannot be cast to java.lang.String
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:326)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:304)
at com.alibaba.fastjson.serializer.ASMSerializer_93_PackageMetaData.write(Unknown Source)
at com.alibaba.fastjson.serializer.ASMSerializer_2_BasicIfcModel.write(Unknown Source)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:304)
at com.alibaba.fastjson.serializer.ASMSerializer_1_IfcOrganizationImpl.write(Unknown Source)
at com.alibaba.fastjson.serializer.CollectionCodec.write(CollectionCodec.java:96)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:275)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:648)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:590)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:555)
at cn.dlb.bim.utils.ByteUtil.toByteArray(ByteUtil.java:27)
at cn.dlb.bim.service.TestBimService.insert(TestBimService.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl cannot be cast to java.lang.String
at com.alibaba.fastjson.serializer.SerializeWriter.write(SerializeWriter.java:1104)
at com.alibaba.fastjson.serializer.ASMSerializer_96_EAnnotationImpl.write(Unknown Source)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:304)
at com.alibaba.fastjson.serializer.ASMSerializer_95_EDataTypeImpl.write(Unknown Source)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:304)
at com.alibaba.fastjson.serializer.ASMSerializer_94_EAttributeImpl.write(Unknown Source)
at com.alibaba.fastjson.serializer.ListSerializer.write(ListSerializer.java:126)
at com.alibaba.fastjson.serializer.FieldSerializer.writeValue(FieldSerializer.java:222)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:296)
... 36 more

64jmpszr

64jmpszr1#

不知道怎么解决这个问题?

zbwhf8kr

zbwhf8kr2#

目前用的版本1.2.28

ojsjcaue

ojsjcaue3#

@shenan4321 org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl cannot be cast to java.lang.String
强转错误,EStringToStringMapEntryImpl不能用getString方法

相关问题