JSON String Convert to Complex Java Class hierarchy in REST full API

JSON String Convert to Complex Java Class hierarchy in REST full API



I define a Complex Structure for Criteria as bellow, I want use this structure for creating Search query in GWT client Side to send it to server by rest API(restyGWT). in server, GSON or Jackson can not convert it to java Object, because I use interface definition in SearchCriteriaCollection, so Gson or jackson can not specify which implementation used in Object.



[class diagram of SerachCriteriaCollection] https://www.dropbox.com/s/ruvmzgo0odtaetf/class_diagram.jpg?dl=0



I was hoping that the use of the package name in criteria would be useful because I want use package name in server side by reflection to convert json string to java Object, but in Client Side in GWT I can not use Reflection, because GWT can not support it.
I believe that this problem is not related to GWT, in angularJs based applications or others client web application deals with this situation. what is the solution at this situation?



for example create bellow json query:



"offset": 0,
"limit": 50,
"pageSize": 10,
"criterias":
"criterions": [

"criterions": [

"name": "category.id",
"value":
"value": 10
,
"operation": "EQUAL"
,

"name": "category.id",
"value":
"value": 10
,
"operation": "EQUAL"

],
"operation": "AND"

],
"operation": "AND"




by below javaCode:


// -----------------------------------------------------------
// dynamic search criteria collection
SearchCriteriaCollection searchCriteriaCollection = new SearchCriteriaCollection();
Criteria criterias_1 = Restrictions.equal(KeyModel.CATEGORY_FEILD_NAME + "." + CategoryModel.ID_FEILD_NAME, new LongValue(selectedCategoryId));
Criteria criterias_2 = Restrictions.equal(KeyModel.CATEGORY_FEILD_NAME + "." + CategoryModel.ID_FEILD_NAME, new LongValue(selectedCategoryId));
Criteria criterias = Restrictions.and(criterias_1,criterias_2);
searchCriteriaCollection.setCriterias(criterias);
// -----------------------------------------------------------



but at server jackson can not convert json string to javaObject and throw bellow exception:


com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `ir.projects.core.filter.Criteria` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj