Monday 13 March 2017

IllegalStateException:Target object must not be null Spring Boot

I am developing a platform based on the micro services architecture (JAX-RS) and a nodeJS API.

I have a problem adding an object to the database, because it always marks null by spring boot.

*Here is my REST controller code (JAX-RS):

@RequestMapping(value="/Ajouter")
    public Actifs AjouterActifs( @RequestBody(required=false) Actifs act){

        return Actif.saveT(act);
    }

*Here the code node API to add the object "Actifs":

app.post("/actifs/ajouterActif",function (req,res) {

        var addActif = JSON.stringify(req.body);
        console.log("params: "+addActif);

        try {
            http.get(url+"/Ajouter?act="+addActif, function (response) {
                var dataJson ='';
                response.on('data',function(data){
                    dataJson += data;
                });
                response.on('end',function(){
                    try
                    {
                        var addAct = JSON.parse(dataJson);
                    }
                    catch(err) {
                        console.log('erreur de retourner l\'actif  -->', +err);
                    }
                    res.json(addAct);
                });
            });
        }
        catch(e) {
            console.log("erreur d'ajouter les info d'actif -->", +e);
        }
    });

*Postman: enter image description here

I get this error:

{ "timestamp": 1489400224236,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.InvalidDataAccessApiUsageException",
"message": "Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Target object must not be null; nested exception is java.lang.IllegalArgumentException: Target object must not be null",
"path": "/Actifs/Ajouter" }

How to avoid a null object passing from node JS to the JAX-RS service ?

thank you for helping me,



via emile01

No comments:

Post a Comment