Nilkin
Nilkin

Reputation: 47

Postman send JSON Object containing List<Object>

I am currently working on project where the current implementation written by others takes a message containing a List that can be interpreted as 4 other Object types, as stated in its XmlElements list. I am currently writing a Rest implementation for this, and my question is whether Postman can send a message body containing a List of type Object. When I send a raw JSON body to test, I receive my object, but its list is null.

Here is an example of a message with only one type.

{

    "listObject" : [
        {
            "type1":{
                "var1": "String",
                "var2": "String",
                "var3": "Instance",
                "var4": "String",
                "var5": "String",
                "var6": Integer,
            }
        }
    ]
}

Here is my code for receiving posts

@RestController
public class ExampleRestController{
    
    @Autowired
    ServiceObject service;

    @PostMapping(value="path/example", produces=MediaType.APPLICATION_JSON_VALUE)
    public ResponseType example(@RequestBody ExampleObj obj){
        return service.handleObj(obj);
    }
}

public class ExampleObj{
    
    protected List<Object> listObject;
    
    public List<Object> getListObject{
        if(listObject == null)
            listObject = new ArrayList<Object>();
        return listObject;
    }
}

When writing the message body, I have made sure to use the variable names for the object I am trying to test, yet when I test I receive a list that is null.

Is it possible to send a List of type Object with Postman?

Upvotes: 0

Views: 950

Answers (1)

Ferry
Ferry

Reputation: 404

yes, jackson will treat any Object as LinkedHashMap internally.

Upvotes: 1

Related Questions