я старался построить пример, чтобы спасти мою enity, как показано ниже:использование GeoJsonPoint с MongoDB и пружинными данными
класса ресурсов имеет ResourceDetail, в котором я определил GeoJsonPoint.
@Document(collection = "Resource")
public class Resource implements Serializable {
/**
*
*/
private static final Long serialVersionUID = 1L;
@Id
private Long id;
private String name;
private Integer age;
private String orgName;
private String resourceType;
private String department;
private boolean showPrice;
private Integer price;
private ResourceDetail resourceDetail;
}
@Document(collection = "ResourceDetail")
public class ResourceDetail implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String identityNumber;
@DateTimeFormat(iso = ISO.DATE)
private Date birthDate;
private String addressLine1;
private String addressLine2;
private String specialization;
private GeoJsonPoint location;
}
Я добавил следующее картографа также в AppConfig:
@Configuration
@ComponentScan(basePackages = "com.test")
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {
@Bean
public MongoDbFactory mongoDbFactory() throws Exception {
return new SimpleMongoDbFactory(new MongoClient(), "test");
}
@Bean
public MongoTemplate mongoTemplate() throws Exception {
MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory());
return mongoTemplate;
}
/**
* Read JSON data from disk and insert those stores.
*
* @return
*/
public @Bean ObjectMapper repositoryPopulator() {
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(GeoJsonPoint.class, GeoJsonPointMixin.class);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper;
}
static abstract class GeoJsonPointMixin {
GeoJsonPointMixin(@JsonProperty("longitude") double x, @JsonProperty("latitude") double y) {
}
}
}
Я получаю эту ошибку:
{
"timestamp": 1445857673601,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "Could not read JSON: No suitable constructor found for type [simple type, class org.springframework.data.mongodb.core.geo.GeoJsonPoint]: can not instantiate from JSON object (need to add/enable type information?)\n at [Source: [email protected]; line: 13, column: 25] (through reference chain: com.appointment.domain.Resource[\"resourceDetail\"]->com.appointment.domain.ResourceDetail[\"location\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class org.springframework.data.mongodb.core.geo.GeoJsonPoint]: can not instantiate from JSON object (need to add/enable type information?)\n at [Source: [email protected]; line: 13, column: 25] (through reference chain: com.appointment.domain.Resource[\"resourceDetail\"]->com.appointment.domain.ResourceDetail[\"location\"])",
"path": "/rest/resource/add"
}
Я использовал этот формат, чтобы спасти мою enity с GeoJsonPoint:
{
"name":"Test",
"age": 32,
"orgName":"testOrg",
"resourceType":"testresourcType",
"price":1200,
"department":"testDepartment",
"resourceDetail": {
"identityNumber": "3",
"birthDate": "2000-10-10",
"location" : { "latitude":40.743827, "longitude":-73.989015 }
}
Пожалуйста, помогите мне решить эту проблему. Спасибо