[Solved] Sping controller Receives list entity parameter Error: nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256

When the controller in spin receives entity parameters
if there is a list attribute in the entity, an error will be reported when the list value is too large

public class Model{
    private List<String> strings;
}

Error Messages: “Invalid property ‘rynrlist[256]’ of bean class [com.ac.intellsecurity.model.exam.records.ExamTrainingRecordsModel]: Index of out of bounds in property path ‘rynrlist[256]’; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256”

Reason:

Solution:
1. modified into jsonobject to receive parameters and then converted into an entity (recommended)

@RestController
@RequestMapping("/controller")
public class Controller {

    //Before Modified
    @PostMapping("/addModel")
        public AjaxResult addModel(Model model){
        //.........
    }

    //Modified
    @PostMapping("/addModel")
    public AjaxResult addModel(JSONObject json){
        //.........
        Model model = JSONObject.parseObject(json.toJSONString(),Model.class);
    }
}    

2. Add method in controller

@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.setAutoGrowNestedPaths(true);
    binder.setAutoGrowCollectionLimit(1024);
}

 

Similar Posts: