Imagine SearchAction{

private List<Record> 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:
<action name="SearchmarkSelectedArticlesJSON" class="searchAction"
method="markSelectedArticles">
        <interceptor-ref name="json"/>
</action>

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

Reply via email to