Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] mongo GeoJsonPoint类型的支持 bug #483

Closed
lmh2017 opened this issue Jun 17, 2022 · 3 comments
Closed

[BUG] mongo GeoJsonPoint类型的支持 bug #483

lmh2017 opened this issue Jun 17, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@lmh2017
Copy link

lmh2017 commented Jun 17, 2022

问题描述

简要描述您碰到的问题。

已知fastejson扩展包支持对mongo GeoJsonPoint类型的支持。 ps:2.0.7版本已经引入了
依赖

  <dependency>
              <groupId>com.alibaba.fastjson2</groupId>
              <artifactId>fastjson2-extension</artifactId>
              <version>2.0.7</version>
   </dependency>

json字符串为下:

{
  "gpsAddress": {
	  "coordinates": [113.92966694974888, 22.543470524848683],
	  "type": "Point",
	  "x": 113.92966694974888,
	  "y": 22.543470524848683
  }
}

bean对象 属性

private GeoJsonPoint gpsAddress;

解析

    @Test
    public void testGpsMO(){
        com.alibaba.fastjson2.JSON.register(GeoJsonReaderModule.INSTANCE);
        com.alibaba.fastjson2.JSON.register(GeoJsonWriterModule.INSTANCE);
        String str = "{\n" +
                "  \"gpsAddress\": {\n" +
                "\t  \"coordinates\": [113.92966694974888, 22.543470524848683],\n" +
                "\t  \"type\": \"Point\",\n" +
                "\t  \"x\": 113.92966694974888,\n" +
                "\t  \"y\": 22.543470524848683\n" +
                "  }\n" +
                "}";
        DispatchPositionInfoMO dispatchPositionInfoMO = com.alibaba.fastjson2.JSON.parseObject(str,DispatchPositionInfoMO.class);
        System.out.println(dispatchPositionInfoMO.toString());
    }

报错如下:

       com.alibaba.fastjson2.JSONException: illegal character ,

	at com.alibaba.fastjson2.JSONReaderUTF16.readFieldNameHashCode(JSONReaderUTF16.java:635)
	at com.alibaba.fastjson2.support.spring.data.mongodb.GeoJsonPointReader.readObject(GeoJsonPointReader.java:34)
	at com.alibaba.fastjson2.support.spring.data.mongodb.GeoJsonPointReader.readObject(GeoJsonPointReader.java:9)
	at com.alibaba.fastjson2.reader.ObjectReader_1.readObject(Unknown Source)
	at com.alibaba.fastjson2.JSON.parseObject(JSON.java:453)
	at com.fujfu.drainage.web.controller.FastJson2Test.testGpsMO(FastJson2Test.java:59)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at 

经过反复测试发现,现在的解析类 GeoJsonPointReader 只支持如下格式,type和coordinates换个位置不行,增加多余属性也不行,也会报错。

        String str = "{" +
                "\"gpsAddress\": {\n" +
                "\t\t\"type\": \"Point\",\n" +
                "\t\t\"coordinates\": [113.930509970399, 22.525810599744]" +
                "}\n" +
                "}";

麻烦请修复这个问题,因为前端参数传进来没法保证顺序和多余属性。

@lmh2017 lmh2017 added the bug Something isn't working label Jun 17, 2022
@lmh2017 lmh2017 changed the title [BUG] [BUG] mongo GeoJsonPoint类型的支持 bug Jun 17, 2022
@wenshao wenshao added this to the 2.0.8 milestone Jun 17, 2022
@wenshao
Copy link
Member

wenshao commented Jun 17, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.8-SNAPSHOT/
问题已经修复,请帮忙用2.0.8-SNAPSHOT验证

@wenshao
Copy link
Member

wenshao commented Jun 25, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.8
问题已经修复,请用新版本

@wenshao wenshao closed this as completed Jun 25, 2022
@lmh2017
Copy link
Author

lmh2017 commented Jun 27, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.8 问题已经修复,请用新版本

好的,已验证,我们准备切换到生产环境,有问题再跟你们提issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants