[英]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.我目前正在从事一个项目,在该项目中,其他人编写的当前实现采用包含可以解释为其他 4 种 Object 类型的列表的消息,如其 XmlElements 列表中所述。 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.我目前正在为此编写 Rest 实现,我的问题是 Postman 是否可以发送包含 Object 类型列表的消息正文。 When I send a raw JSON body to test, I receive my object, but its list is null.当我发送一个原始的 JSON 主体进行测试时,我收到了我的 object,但它的列表是 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.在编写消息正文时,我确保使用我正在尝试测试的 object 的变量名称,但是当我测试时,我收到一个列表 null。
Is it possible to send a List of type Object with Postman?是否可以使用 Postman 发送类型为 Object 的列表?
yes, jackson will treat any Object as LinkedHashMap internally.是的,jackson 将在内部将任何 Object 视为 LinkedHashMap。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.