我有这样的服务:
public interface FireService {
void addTags(String sessionId, List<TagCreateRequest> tags);
}
这里 TagCreateRequest 是:
@MetaClass(name = "...")
public class TagCreateRequest extends AbstractNotPersistentEntity implements Serializable {
@MetaProperty(mandatory = true)
protected TagType type;
@MetaProperty(mandatory = true)
protected Double time;
@MetaProperty
protected String text;
public void setType(TagType type) {
this.type = type;
}
public TagType getType() {
return type;
}
public void setTime(Double time) {
this.time = time;
}
public Double getTime() {
return time;
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
我的问题是当我尝试向这样的方法发出 REST 请求时addTags
:
http://localhost:8080/app/rest/v2/services/fire_FireService/addTags
{
"sessionId": "1417270d-31cb-be3c-e583-4b172b4183a9",
"tags": [
{
"type": "fire",
"time": 12.333
},
{
"type": "text",
"time": 15.12,
"text": "Test!!!"
}
]
}
我得到的信息EntitySerializationException
告诉我,MetaClass
未定义实体:
EntitySerializationException: Cannot deserialize an entity. MetaClass is not defined
我试图查看平台如何确定MetaClass
并发现奇怪的事情。如果服务参数是Collection
,则传递MetaClass
的是null
:
@Component("cuba_RestParseUtils")
public class RestParseUtils {
...
public Object toObject(Class clazz, String value) throws ParseException {
...
if (Collection.class.isAssignableFrom(clazz)) {
return entitySerializationAPI.<Entity>entitiesCollectionFromJson(value, null);
}
...
}
...
}
在这种情况下我该怎么办?