GeoJsonPoint反序列化问题序列化对象类
package pojo;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import pes.ObjectId;
import org.springframework.data.annotation.Id;
import org.GeoJsonPoint;
import org.db.core.index.CompoundIndex;
import org.db.core.index.Indexed;
import org.db.core.mapping.Document;
import java.beans.Transient;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection ="ur_location")
@CompoundIndex(name ="location_index", def ="{'location': '2dsphere'}")
public class UrLocation implements java.io.Serializable{
private static final long rialVersionUID =4508868382007529970L;
@Id
private ObjectId id;
@Indexed
private Long urId;//⽤户id
private GeoJsonPoint location;//x:经度 y:纬度
private String address;//位置描述梦到跟别人打架
private Long created;//创建时间
private Long updated;//更新时间
private Long lastUpdated;//上次更新时间
}
测试类
package com.st;
import com.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
中国的旅游胜地
import pojo.UrLocation;
import pes.ObjectId;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.Point;
import org.GeoJsonPoint;
我很孤独import java.io.IOException;
import java.util.Iterator;
小学生科技小发明import java.util.List;
public class GeoJsonPointObjectMapper {
private static final ObjectMapper objectMapper =new ObjectMapper();
private String gps = null;
private String gps2 = null;
@Test
@Test
public void geoJsonPointObjectMapperTest(){
try{
UrLocation urLocation =new UrLocation();
urLocation.tUrId(1L);
/
/ urLocation.tId(new ObjectId());
urLocation.tCreated(System.currentTimeMillis());
//这⾥封装了GeoJsonPoint对象
urLocation.tLocation(new GeoJsonPoint(new Point(113.33831,23.137335)));
urLocation.tAddress("中国");
urLocation.tUpdated(System.currentTimeMillis());
urLocation.tLastUpdated(System.currentTimeMillis());
gps = objectMapper.writeValueAsString(urLocation);
System.out.println(gps);
System.out.println("+++++++++");
GeoJsonPoint geoJsonPoint =new GeoJsonPoint(new Point(666.33831,666.137335));
gps2 = objectMapper.writeValueAsString(geoJsonPoint);
}catch(JsonProcessingException e){
e.printStackTrace();
}
}
@After
public void gpsremapper(){
try{
GeoJsonPoint geoJsonPoint = adValue(gps2, GeoJsonPoint.class);
System.out.println(geoJsonPoint);
System.out.println("==============");
System.out.println("遍历节点拿⽂本(也就是拿字符串),能拿到");
JsonNode jsonNode = adTree(gps);
List<String> valuesAsText = ("location").findValuesAsText("x");
valuesAsText.forEach(System.out::println);
Iterator<String> location = ("location").fieldNames();
location.forEachRemaining(System.out::println);
System.out.println("==============");
System.out.println("直接字节码对象反序列化就报找不到反序列化字段");
UrLocation urLocation = adValue(gps, UrLocation.class);
System.out.println(urLocation);
}catch(Exception e){
e.printStackTrace();感受的近义词
}
}
}
C:\Java\jdk1.8.0_152\ -ea -lic.buffer.size=1048576"-javaagent:D:\Rj\JetBrains\IntelliJ IDEA 2020.3\lib\idea_rt.jar=63532:D:\Rj\Jet Brains\IntelliJ IDEA 2020.3\bin"-ding=UTF-8-classpath "D:\Rj\JetBrains\IntelliJ IDEA 2020.3\lib\idea_rt.jar;D:\Rj\JetBrains\IntelliJ IDEA 2020.3\plu gins\junit\lib\junit5-rt.jar;D:\Rj\JetBrains\IntelliJ IDEA 2020.3\plugins\junit\lib\junit-rt.jar;C:\Java\jdk1.8.0_152\jre\lib\charts.jar;C:\Java\jdk1.8.0_152\jre\lib\d eploy.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\access-bridge-64.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\cldrdata.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\dnsns.jar;C:\Java\ jdk1.8.0_152\jre\lib\ext\jaccess.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\jfxrt.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\localedata.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\nas horn.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\sunec.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\sunjce_provider.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\sunmscapi.jar;C:\Java \jdk1.8.0_152\jre\lib\ext\sunpkcs11.jar;C:\Java\jdk1.8.0_152\jre\lib\ext\zipfs.jar;C:\Java\jdk1.8.0_152\jre\lib\javaws.jar;C:\Java\jdk1.8.0_152\jre\lib\jce.jar;C:\
Java\jdk1.8.0_152\jre\lib\jfr.jar;C:\Java\jdk1.8.0_152\jre\lib\jfxswt.jar;C:\Java\jdk1.8.0_152\jre\lib\js.jar;C:\Java\jdk1.8.0_152\jre\lib\management-agent.jar; C:\Java\jdk1.8.0_152\jre\lib\plugin.jar;C:\Java\jdk1.8.0_152\jre\lib\resources.jar;C:\Java\jdk1.8.0_152\jre\lib\rt.jar;D:\ProjectMyTwo\AKW\mytanhua\rver\ta rget\test-class;D:\ProjectMyTwo\AKW\mytanhua\rver\target\class;D:\ProjectMyTwo\AKW\mytanhua\dubbo\dubbo-interface\target\class;D:\maven\ repository\org\projectlombok\lombok\1.18.4\lombok-1.18.4.jar;D:\ProjectMyTwo\AKW\mytanhua\Commom\target\class;D:\maven\repository\org\mongod b\mongodb-driver-sync\3.9.1\mongodb-driver-sync-3.9.1.jar;D:\maven\repository\org\mongodb\bson\3.8.2\bson-3.8.2.jar;D:\maven\repository\org\mongod b\mongodb-driver-core\3.8.2\mongodb-driver-core-3.8.2.jar;D:\maven\repository\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.
9.jar;D:\maven\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\maven\repository\com\fasterxml\jackson\c ore\jackson-core\2.9.9\jackson-core-2.9.9.jar;D:\maven\repository\com\github\tobato\fastdfs-client\1.26.7\fastdfs-client-1.26.7.jar;D:\maven\repository\org\s lf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\maven\repository\org\sl
f4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;D:\maven\repository\commons-beanutils\com mons-beanutils\1.9.3\commons-beanutils-1.9.3.jar;D:\maven\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\ maven\repository\org\apache\commons\commons-pool2\2.6.0\commons-pool2-2.6.0.jar;D:\maven\repository\org\springframework\spring-core\5.1.2.RELE ASE\spring-core-5.1.2.RELEASE.jar;D:\maven\repository\org\springframework\spring-jcl\5.1.2.RELEASE\spring-jcl-5.1.2.RELEASE.jar;D:\maven\repository\ org\hibernate\validator\hibernate-validator\6.0.13.Final\hibernate-validator-6.0.13.Final.jar;D:\maven\repository\javax\validation\validation-api\2.0.1.Final\va lidation-api-2.0.1.Final.jar;D:\maven\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\maven\repository\com\fasterxml\c lassmate\1.4.0\classmate-1.4.0.jar;D:\maven\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.0.RELEASE\spring-boot-autoconfigure-2.
1.0.RELEASE.jar;D:\maven\repository\org\springframework\boot\spring-boot\
2.1.0.RELEASE\spring-boot-2.1.0.RELEASE.jar;D:\maven\repository\org\sprin gframework\spring-context\5.1.2.RELEASE\spring-context-5.1.2.RELEASE.jar;D:\maven\repository\org\springframewor
k\spring-aop\5.1.2.RELEASE\spring-aop-5.1.2.RELEASE.jar;D:\maven\repository\org\springframework\spring-beans\5.1.2.RELEASE\spring-beans-5.1.2.RELEASE.jar;D:\maven\repository\org\
aop-5.1.2.RELEASE.jar;D:\maven\repository\org\springframework\spring-beans\5.1.2.RELEASE\spring-beans-5.1.2.RELEASE.jar;D:\maven\repository\org\ springframework\spring-expression\5.1.2.RELEASE\spring-expression-5.1.2.RELEASE.jar;D:\maven\repository\net\coobird\thumbnailator\0.4.8\thumbnailat or-0.4.8.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-web\2.1.0.RELEASE\spring-boot-starter-web-2.1.0.RELEASE.jar;D:\maven\r epository\org\springframework\boot\spring-boot-starter\2.1.0.RELEASE\spring-boot-starter-2.1.0.RELEASE.jar;D:\maven\repository\org\springframework\b oot\spring-boot-starter-logging\2.1.0.RELEASE\spring-boot-starter-logging-2.1.0.RELEASE.jar;D:\maven\repository\ch\qos\logback\logback-classic\1.2.3\lo gback-classic-1.2.3.jar;D:\maven\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\maven\repository\org\apache\logging\log4j\log4j-t o-slf4j\2.11.1\log4j-to-slf4j-2.11.1.jar;D:\maven\repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;D:\mave
n\repository\org\slf4j\jul-to-s lf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\maven\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\maven\repository\org\yaml \snakeyaml\1.23\snakeyaml-1.23.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-json\2.1.0.RELEASE\spring-boot-starter-json-2.1.0. RELEASE.jar;D:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;D:\maven\repository\com\fa sterxml\jackson\datatype\jackson-datatype-jsr310\2.9.9\jackson-datatype-jsr310-2.9.9.jar;D:\maven\repository\com\fasterxml\jackson\module\jackson-mod ule-parameter-names\2.9.9\jackson-module-parameter-names-2.9.9.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.0.R ELEASE\spring-boot-starter-tomcat-2.1.0.RELEASE.jar;D:\maven\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.12\tomcat-embed-core-9.0 .12.jar;D:\maven\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.12\tomcat-embed-el-9.0.12.jar;D:\maven\repository\org\apache\tomcat\embed \tomcat-embed-websocket\9.0.12\tomcat-embed-websocket-9.0.12.jar;D:\maven\repository\org\springframework\spring-web\5.1.2.RELEASE\spring-web-5.
1.2.RELEASE.jar;D:\maven\repository\org\springframework\spring-webmvc\5.1.2.RELEASE\spring-webmvc-5.1.2.RELEASE.jar;D:\maven\repository\org\ap ache\rocketmq\rocketmq-spring-boot-starter\2.0.3\rocketmq-spring-boot-starter-2.0.3.jar;D:\maven\repository\org\apache\rocketmq\rocketmq-spring-boot\ 2.0.3\rocketmq-spring-boot-2.0.3.jar;D:\maven\repository\org\apache\rocketmq\rocketmq-acl\4.5.1\rocketmq-acl-4.5.1.jar;D:\maven\repository\org\apache\ rocketmq\rocketmq-logging\4.5.1\rocketmq-logging-4.5.1.jar;D:\maven\repository\org\apache\rocketmq\rocketmq-srvutil\4.5.1\rocketmq-srvutil-4.5.1.jar;D:\ maven\repository\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;D:\maven\repository\org\springframework\spring-messaging\5.1.2.RELEASE\spring-m essaging-5.1.2.RELEASE.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-validation\2.1.0.RELEASE\spring-boot-starter-validation-2.
1.0.RELEASE.jar;D:\maven\repository\org\apache\rocketmq\rocketmq-client\4.6.0\rocketmq-client-4.6.0.jar;D:\maven\repository\org\apache\rocketmq\rock etmq-common\4.6.0\rocketmq-common-4.6.0.jar;D:\maven\repository\org\apache\rocketmq\rocketmq-remoting\4.6.0\rocketmq-remoting-4.6.0.jar;D:\mave n\repository\com\alibaba\fastjson\1.
2.61\fastjson-1.2.61.jar;D:\maven\repository\io\netty\netty-all\4.1.32.Final\netty-all-4.1.32.Final.jar;D:\
maven\repository\i o\netty\netty-tcnative-boringssl-static\2.0.17.Final\netty-tcnative-boringssl-static-2.0.17.Final.jar;D:\maven\repository\commons-validator\commons-validato r\1.6\commons-validator-1.6.jar;D:\maven\repository\commons-digester\commons-digester\1.8.1\commons-digester-1.8.1.jar;D:\maven\repository\commo ns-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-test\2.1.0.RELEASE\spring-b oot-starter-test-2.1.0.RELEASE.jar;D:\maven\repository\org\springframework\boot\spring-boot-test\2.1.0.RELEASE\spring-boot-test-2.1.0.RELEASE.jar;D:\ maven\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.1.0.RELEASE\spring-boot-test-autoconfigure-2.1.0.RELEASE.jar;D:\maven\re pository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\maven\repository\net\minidev\json-smart\2.3\json-smart-2.
3.jar;D:\maven\repository\ne t\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\maven\repository\org\ow2\asm\asm\5.0.4\asm-5.0.
4.jar;D:\maven\repository\org\asrtj\asrtj-c ore\3.11.1\asrtj-core-3.11.1.jar;D:\maven\repository\org\mockito\mockito-core\2.23.0\mockito-core-2.23.0.jar;D:\maven\repository\net\bytebuddy\byte-bu ddy\1.9.3\byte-buddy-1.9.3.jar;D:\maven\repos
itory\net\bytebuddy\byte-buddy-agent\1.9.3\byte-buddy-agent-1.9.3.jar;D:\maven\repository\org\objenesis\o bjenesis\2.6\objenesis-2.6.jar;D:\maven\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\maven\repository\org\hamcrest\hamcrest-libr ary\1.3\hamcrest-library-1.3.jar;D:\maven\repository\org\skyscreamer\jsonasrt\1.
5.0\jsonasrt-1.5.0.jar;D:\maven\repository\com\vaadin\external\google \android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\maven\repository\org\springframework\spring-test\5.1.2.RELEASE\spring-te st-5.1.2.RELEASE.jar;D:\maven\repository\org\xmlunit\xmlunit-core\2.
6.2\xmlunit-core-2.6.2.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-data-redis\2.1.0.RELEASE\spring-boot-starter-data-redis-2.1.0.RELEASE.jar;D:\maven\repository\org\springframework\data\spring-data-redis\2.1.2. RELEASE\spring-data-redis-2.1.2.RELEASE.jar;D:\maven\repository\org\springframework\data\spring-data-keyvalue\2.1.2.RELEASE\spring-data-keyvalue-2.1.2.RELEASE.jar;D:\maven\repository\org\springframework\spring-tx\5.1.2.RELEASE\spring-tx-5.1.
2.RELEASE.jar;D:\maven\repository\org\springframew ork\spring-oxm\5.1.2.RELEASE\spring-oxm-5.1.2.RELEASE.jar;D:\maven\repository\org\springframework\spring-context-support\5.1.2.RELEASE\spring-co ntext-support-5.1.2.RELEASE.jar;D:\maven\repository\io\lettuce\lettuce-core\5.1.2.RELEASE\lettuce-core-5.1.2.RELEASE.jar;D:\maven\repository\io\project reactor\reactor-core\3.2.2.RELEASE\reactor-core-3.2.2.RELEASE.jar;D:\maven\repository\org\reactivestreams\reactive-streams\1.0.2\reactive-streams-1.0 .2.jar;D:\maven\repository\io\netty\netty-common\4.1.29.Final\netty-common-4.1.29.Final.jar;D:\maven\repository\io\netty\netty-transport\4.1.29.Final\netty -transport-4.1.29.Final.jar;D:\maven\repository\io\netty\netty-buffer\4.1.29.Final\netty-buffer-4.1.29.Final.jar;D:\maven\repository\io\netty\netty-resolver\4.1.
29.Final\netty-resolver-4.1.29.Final.jar;D:\maven\repository\io\netty\netty-handler\4.1.29.Final\netty-handler-4.1.29.Final.jar;D:\maven\repository\io\netty\n etty-codec\4.1.29.Final\netty-codec-4.1.29.Final.jar;D:\maven\repository\com\aliyun\oss\aliyun-sdk-oss\2.8.3\aliyun-sdk-oss-2.8.3.jar;D:\maven\repository\o rg\apache\httpcomponents\httpclient\4.5.6\httpclient-4.5.6.jar;D:\maven\repository\org\apache\httpcomponents\httpcore\4.4.10\httpcore-4.4.10.jar;D:\mave n\repository\org\jdom\jdom\1.1\jdom-1.1.jar;D:\maven\repository\joda-time\joda-ti
me\2.9.9\joda-time-2.9.9.jar;D:\maven\repository\com\alibaba\boot\dubbo -spring-boot-starter\0.2.0\dubbo-spring-boot-starter-0.2.0.jar;D:\maven\repository\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.j ar;D:\maven\repository\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;D:\maven\repository\com\google\guava\guava\16.0.1\guava-16.0.
1.jar;D:\maven\repository\com\alibaba\boot\dubbo-spring-boot-autoconfigure\0.
2.0\dubbo-spring-boot-autoconfigure-0.2.0.jar;D:\maven\repository\com\ali baba\dubbo\2.6.4\dubbo-2.6.4.jar;D:\maven\repository\org\javassist\javassist\
3.20.0-GA\javassist-3.20.0-GA.jar;D:\maven\repository\org\jboss\netty\netty\3 .2.5.Final\netty-3.2.5.Final.jar;D:\maven\repository\org\apache\zookeeper\zookeeper\3.
4.13\zookeeper-3.4.13.jar;D:\maven\repository\org\slf4j\slf4j-log4j1 2\1.7.25\slf4j-log4j12-1.7.2
5.jar;D:\maven\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;D:\maven\repository\jline\jline\0.9.94\jline-0.9.94.jar;D:\maven\reposit ory\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar;D:\maven\repository\io\netty\netty\3.10.
6.Final\netty-3.10.6.Final.jar;D:\m aven\repository\com\github\sgroschupf\zkclient\0.1\zkclient-0.1.jar;D:\maven\repository\org\apache\commons\commons-lang3\3.7\commons-lang3-3.
7.jar; D:\maven\repository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;D:\maven\repository\com\baomidou\mybatis-plus\3.1.1 \mybatis-plus-3.1.1.jar;D:\maven\repository\com\baomidou\mybatis-plus-extension\3.1.1\mybatis-plus-extension-3.1.1.jar;D:\maven\repository\com\baomid ou\mybatis-plus-core\3.1.1\mybatis-plus-core-3.1.1.jar;D:\maven\repository\com\baomidou\mybatis-plus-annotation\3.1.1\mybatis-plus-annotation-3.1.1.jar ;D:\maven\repository\com\github\jsqlparr\jsqlparr\1.2\jsqlparr-1.2.jar;D:\maven\repository\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;D:\maven\repo sitory\org\mybatis\mybatis-spring\2.0.1\mybatis-spring-2.0.1.jar;D:\maven\repository\com\baomidou\mybatis-plus-boot-starter\3.1.1\mybatis-plus-boot-start er-3.1.1.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.0.RELEASE\spring-boot-starter-jdbc-2.1.0.RELEASE.jar;D:\maven\r epository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;D:\maven\repository\org\springframework\spring-jdbc\5.1.2.RELEASE\spring-jdbc-5.1.2.RELEASE.j ar;D:\maven\repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.
1.47.jar;D:\maven\repository\commons-io\commons-io\2.6\commons-io -2.6.jar;D:\maven\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;D:\maven\repository\org\aspectj\aspectjweaver\1.
8.13\aspect jweaver-1.8.13.jar;D:\maven\repository\org\springframework\boot\spring-boot-starter-data-mongodb\2.1.0.RELEASE\spring-boot-starter-data-mongodb-2.
1.0.RELEASE.jar;D:\maven\repository\org\mongodb\mongodb-driver\3.8.2\mongodb-driver-3.8.
2.jar;D:\maven\repository\org\springframework\data\spring-data-mongodb\2.1.2.RELEASE\spring-data-mongodb-2.1.2.RELEASE.jar;D:\maven\repository\org\springframework\data\spring-data-commons\2.1.2.RELE ASE\spring-data-commons-2.1.2.RELEASE.jar;D:\maven\repository\junit\junit\4.12\junit-4.12.jar" junit.JUnitStarter -ideVersion5 -junit4 com.tan st.GeoJsonPointObjectMapper,geoJsonPointObjectMapperTest
{"id":null,"urId":1,"location":{"x":113.33831,"y":23.137335,"type":"Point","coordinates":[113.33831,23.137335]},"address":"中国","created":161063607920 2,"updated":1610636079207,"lastUpdated":1610636079207}
+++++++++
com.fasterxml.InvalidDefinitionException: Cannot construct instance of `org.GeoJsonPoint` (no Creators, like default construct, exist): cannot derialize from Object value (no delegate- or property-bad Creator)
at [Source:(String)"{"x":666.33831,"y":666.137335,"type":"Point","coordinates":[666.33831,666.137335]}"; line:1, column:2]
at com.fasterxml.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.jackson.portBadDefinition(DerializationContext.java:1452)
at com.fasterxml.jackson.databind.DerializationContext.handleMissingInstantiator(DerializationContext.java:1028)
at com.fasterxml.jackson.databind.der.BeanDerializerBa.derializeFromObjectUsingNonDefault(BeanDerializerBa.java:1297)
at com.fasterxml.jackson.databind.der.BeanDerializer.derializeFromObject(BeanDerializer.java:326)
at com.fasterxml.jackson.databind.der.BeanDerializer.derialize(BeanDerializer.java:159)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClo(ObjectMapper.java:4013)
at com.fasterxml.jackson.adValue(ObjectMapper.java:3004)
at com.st.GeoJsonPointObjectMapper.gpsremapper(GeoJsonPointObjectMapper.java:47)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at flect.Method.invoke(Method.java:498)
at org.del.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.del.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
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:69)
at junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at junit.JUnitStarter.main(JUnitStarter.java:53)
Process finished with exit code 0
意思是
com.fasterxml.InvalidDefinitionException:
⽆法构造`org.GeoJsonPoint`的实例(不存在任何创建者,如默认构造⼀样)
:⽆法从Object值反序列化(没有委托)
-或基于属性的创建者)在[来源:(String)“ {” x“:666.33831,” y“:666.137335,” type“:” Point“,” coordinates“:[666.33831,666.137335]}”;⾏:1,列:2]
好的,逼话太多直接看底层的表⾯层是不是这么⼀回事
/*
* Copyright 2015-2018 the original author or authors.
*
* Licend under the Apache Licen, Version 2.0 (the "Licen");
* you may not u this file except in compliance with the Licen.
* You may obtain a copy of the Licen at
*
* www.apache/licens/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licen is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licen for the specific language governing permissions and
* limitations under the Licen.
*/
package org.;
import java.util.Arrays;
import java.util.List;
import org.Point;
/**
* {@link GeoJson} reprentation of {@link Point}.
* {@link GeoJson} reprentation of {@link Point}.
*
* @author Christoph Strobl
* @since 1.7
* @e <a href="geojson/geojson-spec.html#point">geojson/geojson-spec.html#point</a>
*/
public class GeoJsonPoint extends Point implements GeoJson<List<Double>>{
private static final long rialVersionUID =-8026303425147474002L;
private static final String TYPE ="Point";
/**
襟裾怎么读音* Creates {@link GeoJsonPoint} for given coordinates.
*
* @param x
* @param y
*/
public GeoJsonPoint(double x,double y){
super(x, y);
}
/
**
* Creates {@link GeoJsonPoint} for given {@link Point}.
*
* @param point must not be {@literal null}.
*/
public GeoJsonPoint(Point point){
super(point);
}
/*
* (non-Javadoc)
* @e org.GeoJson#getType()
*/
@Override
public String getType(){
青椒鸡胸return TYPE;
}
/*
* (non-Javadoc)
* @e org.GeoJson#getCoordinates()
*/
@Override
public List<Double>getCoordinates(){
return Arrays.asList(Double.valueOf(getX()), Double.valueOf(getY()));
}
折纸步骤}
上⾯代码已经可以看出它没有普通构造器不说,返回值有很多,但是这些都没有经过⼀个有效构造器可以实现传参,不报错就⿁
了,fastjson反序列化就是靠构造器吃饭的,定义了特殊的构造器Point(GeoJsonPoint是Point的亲⼉⼦),它实现了有参构造器,它的⼦类GeoJsonPoint就是打它⽗亲的脸,搞特殊认⼲爹implements GeoJson<List> ,就算了,还不提供个完善的构造器。下⾯为亲爹源码
/*
* Copyright 2010-2018 the original author or authors.
*
* Licend under the Apache Licen, Version 2.0 (the "Licen");
* you may not u this file except in compliance with the Licen.
* You may obtain a copy of the Licen at
*
* www.apache/licens/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licen is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licen for the specific language governing permissions and
* limitations under the Licen.
*/
package org.;