Re: Portlet Issue From Struts version 2.5 to 2.5.5?

2016-12-01 Thread tkofford
Issue reported as
https://issues.apache.org/jira/browse/WW-4722
  



--
View this message in context: 
http://struts.1045723.n5.nabble.com/Portlet-Issue-From-Struts-version-2-5-to-2-5-5-tp5720470p5720475.html
Sent from the Struts - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Can you use type conversion with JSONInterceptor?

2016-12-01 Thread Miguel Almeida
Imagine SearchAction{

private List evaluatedRecords;
}

Record is an interface so to get auto-wiring to work you'd usually
set-up a

SearchAction-conversion.properties:
KeyProperty_evaluatedRecords=id
Element_evaluatedRecords=com.bibliovigilance.model.RecordImpl
CreateIfNull_evaluatedRecords=true


I now want to create an Ajax post on this action. I tried the following:

var evaluatedRecords = [
 {"id": "10672"}
 ]
 
 var json_parameters = {evaluatedRecords:
evaluatedRecords};

$.ajax({
  url: 'SearchmarkSelectedArticlesJSON.action',
  cache: false,
  contentType: 'application/json',
  data: JSON.stringify(json_parameters),
  type: "POST"
});

I believe I need to set-up the JSON interceptor on my action, so I
added:




The problem is that this interceptor doesn't seem to be using the
-conversion.properties, so it throws an error when it tries to
instantiate the Record class:

java.lang.InstantiationException: com.bibliovigilance.model.Record
at java.lang.Class.newInstance(Class.java:368)
at
org.apache.struts2.json.JSONPopulator.convertToCollection(JSONPopulator.java:250)


I also tried removing the Record type in the List ( List
evaluatedRecords). But in this case the JSON deserialization of the
above mentioned ajax call will create a List evaluatedRecords with 1
element, but that element is a Map (I didn't investigate, but I suppose
it'll have id in the key and 10672 in the value).

How would we configure this correctly? Is it possible for the JSON
interceptor to be aware of the -conversion.properties? If not, what
alternatives do you envision?

Thanks!

Miguel