Учитывая контроллер Spring MVC:весна-MVC отсутствует @ класс-информация при размещении DTO из RestyGwt
@RequestMapping(method = RequestMethod.POST consumes = RestApiConstants.JSON, produces = RestApiConstants.JSON)
@ResponseBody
public CustomerDto post(@RequestBody final CustomerDto dto) {
// save it
}
При написании DTO к этому контроллеру, картограф Джексона отсутствует @class
свойства:
2014-11-07 14:20:55 ERROR ... Probably Jackson Mapper has failed.
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property '@class' that is to contain type id (for class com.our.package.CustomerDto)
at [Source: [email protected]; line: 1, column: 988]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property '@class' that is to contain type id (for class com.our.package.CustomerDto)
at [Source: [email protected]; line: 1, column: 988]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:208)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:200)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:138)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:181)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:104)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
...
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property '@class' that is to contain type id (for class com.our.package.CustomerDto)
at [Source: [email protected]; line: 1, column: 988]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.DeserializationContext.wrongTokenException(DeserializationContext.java:784)
...
CustomerDto определяется как специфический подтип абстрактного класса супер PartnerDto:
@JsonSubTypes({
@Type(Customer.class),
@Type(Supplier.class)
})
@JsonTypeInfo(use = Id.CLASS, include = As.PROPERTY, property = "@class")
public abstract class PartnerDto {
// ...
}
public class CustomerDto extends PartnerDto {
// ...
}
RestyGwt сообщений этого CustomerDto:
{
"name": "Testname",
"age": 50,
...
}
Но весна ожидает, что это:
{
"@class": "com.our.package.CustomerDto",
"name": "Testname",
"age": 50,
...
}
Эта проблема возникает так мы переехали весной и RestyGwt использовать картографа Jackson 2 (Spring 4.1.1.RELEASE, RestyGWT 2.0-SNAPSHOT, Jackson 2.3.2). Он работал со старыми версиями (Spring 4.0.7.RELEASE, RestyGWT 1.4, Jackson 1.9.13).
Как я мог справиться с этим?